Results 1 to 3 of 3

Thread: Power Query / DAX solution to Excel formulas (or if this is even appropriate)
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2013
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Power Query / DAX solution to Excel formulas (or if this is even appropriate)

    Hello,

    I've been using Excel for years but have recently been seduced by the appeal of Power BI as a means of providing more 'visually friendly' reports for other users to view and analyse. Whilst I can generally get Excel to do what I want to do (possibly through horrendously inefficient formulas/code), Power BI is just boggling my mind at the moment.

    The issues is such; I have a large data source, that I have no ability to change, that's updated weekly and I download. I've currently written a macro that I run on each download that basically adds a load of additional columns containing formulas - I then save the Excel file and refresh my data source in Power BI, which makes all the visuals look pretty. However, I feel this is essentially a cop out of using Power BI fully - and that the 'proper' solution (given that I can't change the original data source) would be import the unedited report into Power BI directly and then use Power Query / DAX to alter/add to the data as required.

    My Excel data is as below (which I sort by Column F, then R and then S, before my applying formulas in columns V-AD);

    F O P R S U V W X Y Z AA AB AC AD
    1 Employee No. On Cal Roster Date Shift Start Shift Finish Shift Paid On Call? Rest <12hrs >12hrs 7 days >60hrs >72hrs Consecutive 13+ shifts
    2 Number/Text Y/N DD-MM-YY DD-MM-YY HH:MM:SS DD-MM-YY HH:MM:SS H.MM =IF(O2="Y",IF(SUMPRODUCT(($F$2:$F2=F2)*($P$2:$P2=P2))>1,0,1),0) =IF(F2<>F1,23.99,IF(R2="",23.99,IF(S1="",23.99,(R2-S1)*24))) =IF(AND(W2<12,W2>0),1,0) =IF(W2=0,IF(U2+U1>12,1,0),IF(U2>12,1,0)) =SUMIFS(U:U,F:F,F2,P:P,"<="&P2,P:P,">="&P2-6) =IF(Z2>60,IF(P2=P3,0,1),0) =IF(Z2>72,IF(P2=P3,0,1),0) =IF(F2=F1,IF(R2<>"",IF(P2=P1,AC1,IF(P2-P1=1,AC1+1,1)),0),0) =IF(AC2>13,IF(P2=P3,0,1),0)

    The primary reason for needing all the additional formulas is there can be multiple entries for the same employee number (F), on the same date (P) and its important to distinguish if these entries and consecutive or not (based on start start/finish times (R/S)) but at the same time not double counting those entries for other measures. What I want to know/learn how to do is convert the above formulas to DAX and/or Power Query equivalents, if possible? I've attempted this a few times before by googling/reading stuff but usually just end up confusing myself even more.

    The above is actually one of three sheet I do similar things to, but I figure if I can get the above cracked (or even just some of it) I'll be able to figure out the rest from there.

    Any help appreciated and if you need any more info please let me know.

  2. #2
    Board Regular
    Join Date
    Apr 2014
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Power Query / DAX solution to Excel formulas (or if this is even appropriate)

    You can use Power Query feature found under Add Column -> then select Custom Column. All the if formulas you have in column V to Y can be done using the custom column feature.
    This website gives good example on how to use power query if function: https://www.myonlinetraininghub.com/...-if-statements

  3. #3
    New Member
    Join Date
    Jun 2013
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Power Query / DAX solution to Excel formulas (or if this is even appropriate)

    Hi,

    Thanks for your response and link, I managed to get some of the more simpler formulas to work (and can probably figure out the rest when I get a bit more time).

    I think the main thing that threw me was that some of my Excel formulas have a relative reference to a row above or below... and I was trying to do things like;

    Code:
    if [A] - 1 = [B] then "A - 1 = B" else "A-1 <> B"
    Which just wasn't working and then going round in circles by trying to use 'Excel logic'.

    I've since found this and this link, which seem to suggest the way to do it is via some form of index columns. Again, hopefully when I get a bit more time, I can follow through and achieve what I'm after.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •