Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
harshad_barge
Helper I
Helper I

Modifying DAX query to extract correct value

Hi all, 
So I am essentially trying to have a column that is grouped by sum of payment. I want just the cumulative Pay when the payroll date is greater than or equal to the Calculation Date. The grouped values are correct but are repeating hence, when I show it in a table, and sum it, it gives an incorrect value.

The DAX for calculated Pay (N) used is:

Calculated Pay (N) = 

CALCULATE (

SUM ( 'Ordinary Hours'[AUD Total Daily Earnings] ),

ALLEXCEPT (

'Ordinary Hours',

'Ordinary Hours'[Employee Name],

'Ordinary Hours'[Applicable Payroll Date].[Date]

)

)
 
The excel formula that works to desired effect is: 
=IF(AND(E12>=D12,F12<>F13),F12,0)
 
The problem I am facing is that I cannot use it (owing to my limited capabilities; I am quite new to DAX) in DAX as there seems no way to reference previous row

The table and the expected output is as below:


Employee NameAUD Total Daily EarningsCalculatedPayCalculation DateApplicable Payroll DateCalculated Pay (N)Expected (Excel Formula)
Arsher B$327.81$2,031.341/09/2013 0:001/09/2013 0:002031.342031.34
Arsher B$178.60$0.004/09/2013 0:0015/09/2013 0:001959.180
Arsher B$185.73$0.005/09/2013 0:0015/09/2013 0:001959.180
Arsher B$162.02$0.006/09/2013 0:0015/09/2013 0:001959.180
Arsher B$228.94$0.007/09/2013 0:0015/09/2013 0:001959.180
Arsher B$292.16$0.008/09/2013 0:0015/09/2013 0:001959.180
Arsher B$151.95$0.0011/09/2013 0:0015/09/2013 0:001959.180
Arsher B$151.96$0.0012/09/2013 0:0015/09/2013 0:001959.180
Arsher B$151.96$0.0013/09/2013 0:0015/09/2013 0:001959.180
Arsher B$189.94$0.0014/09/2013 0:0015/09/2013 0:001959.180
Arsher B$265.92$1,959.1815/09/2013 0:0015/09/2013 0:001959.181959.18
Arsher B$141.82$0.0018/09/2013 0:0029/09/2013 0:002063.780
Arsher B$166.15$0.0019/09/2013 0:0029/09/2013 0:002063.780
Arsher B$271.50$0.0020/09/2013 0:0029/09/2013 0:002063.780
Arsher B$192.47$0.0021/09/2013 0:0029/09/2013 0:002063.780
Arsher B$269.46$0.0022/09/2013 0:0029/09/2013 0:002063.780
Arsher B$151.95$0.0025/09/2013 0:0029/09/2013 0:002063.780
Arsher B$151.96$0.0026/09/2013 0:0029/09/2013 0:002063.780
Arsher B$187.24$0.0027/09/2013 0:0029/09/2013 0:002063.780
Arsher B$221.65$0.0028/09/2013 0:0029/09/2013 0:002063.780
Arsher B$309.58$2,063.7829/09/2013 0:0029/09/2013 0:002063.782063.78
Daniel Gelat$151.96$0.0030/09/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$171.93$0.001/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$151.95$0.002/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$289.32$0.005/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$333.89$0.006/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$405.20$0.007/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$151.96$0.008/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$141.82$0.009/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$187.85$0.0010/10/2013 0:0013/10/2013 0:002167.230
Daniel Gelat$181.35$0.0011/10/2013 0:0013/10/2013 0:002167.232167.23
Daniel Gelat$169.19$0.0014/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$184.08$0.0015/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$173.75$0.0018/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$247.18$0.0019/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$285.67$0.0020/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$151.96$0.0021/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$151.96$0.0022/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$151.96$0.0023/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$254.88$0.0026/10/2013 0:0027/10/2013 0:002036.550
Daniel Gelat$265.92$2,036.5527/10/2013 0:0027/10/2013 0:002036.552036.55
Daniel Gelat$202.35$0.0030/10/2013 0:0010/11/2013 0:001928.30
Daniel Gelat$190.45$0.0031/10/2013 0:0010/11/2013 0:001928.31928.3

 

How can I modify my Dax to ensure that the output is as per Expected (Excel Formula) column.

p.s. The column that is incorrectly (for intents and purposes) pulling the "Calculated Pay" column is:

CalculatedPay = IF

                (

                    [Calculation Date] < [Applicable Payroll Date],

                    --then--

                    0,

                    --else--

                    VAR payrollId = [Payroll Day ID]

                    VAR empID = [Employee_ID]

                    RETURN CALCULATE(SUM('Ordinary Hours'[AUD Total Daily Earnings]),FILTER('Ordinary Hours',[Payroll Day ID]=payrollId && [Employee_ID]=empID))    

                )
There are a few instances when the calculation date is being skipped at the applicable payroll date hence, the CalculatedPay sum is being skipped and the overall aggregation is thus incorrect.

@Greg_Deckler Grateful for your help so far. I am just not getting there with what I want. I hope this post helps better.


Thank you all!
5 REPLIES 5
Anonymous
Not applicable

If you are trying to add a calculated column to a table in the model, then please spare yourself pain and grief - USE POWER QUERY.

Best
D

Is there any way I can use a DAX calculated table in power query?
If that would be the case, things would be much easier.

No.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Unfortunately as I had thought!
Power BI is made quite good then! Because, if it would go back and forth, I would be in a mess! 😀

Greg_Deckler
Super User
Super User

It seems like I have seen this problem before, is there another similar thread that you posted? If so can you post a link to it so that I can reference it and what I did? I'll take a look at this but there are a lot of dates I need to correct because they don't work with my US English Power BI Desktop. I need to create a Power Query function to convert dates. So annoying!! 🙂


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors