Forum Discussion
Help converting Excel formula to DAX
Hi,
I have the excel formula below but am struggling to convert into DAX format. The formula is:
=SUMIFS(D:D,A:A,"<="&A2,B:B,B2,C:C,C2)
I am trying to get a year to date sum based on period (YYYYMM) and then 2 columns identifying Cost Centre and Cost Type.
Has anyone got an idea how i should do this?
Thanks
Hi Bilal_321321,
The formula =SUMIFS(DSmiley Very Happy,A:A,"<="&A2,B:B,B2,C:C,C2) is converted into DAX as follows.
Create a measure in your Power BI model.Measure = CALCULATE ( SUM ( Table[D] ), FILTER ( Table, AND ( Table[A] <= Table[A2] && Table[B] = Table[B2], Table[C] = Table[C2] ) ) )
Table[A], Table[B],Table[C] and Table[D] are column in Table, while Table[A2], Table[B2] and Table[C2] are fixed value in Table. Please replace them to yours, you will get expected result.
Best Regards,
Angelia
3 Replies
- TomMartensSuper User
Hey,
I'm pretty sure that it will be possible to re-write the Excel-Formula, but I would recommend that you change your model in accordance to some best practice modeling.
Almost everything for time/date related can be found here
www.daxpatterns.com/time-patterns
Hopefully this gets you started
Regards
Tom
- MFelixSuper User
Hi Bilal_321321,
You should use a Calculated formula in order to achieve the expected result, however without details you should have anything like this:
Measure = CALCULATE ( SUM ( Table[Column1] ), VALUES ( Table[Column2] ) <= MAX ( Table[Column2] ), VALUES ( Table[Column3] ) = MAX ( Table[Column3] ) )Calculate allows you to make several complex aggregations (sum, averages, ...) and apply filters and slicing to the formula. Check this link but be aware that you also need to see the rest of DAX, you need to have an understanding of row and table context.
Chek the SQLBI to get information and training.
Again without additional data cannot give you the expected result.
Regards,
MFelix
- v-huizhn-msftMicrosoft Employee
Hi Bilal_321321,
The formula =SUMIFS(DSmiley Very Happy,A:A,"<="&A2,B:B,B2,C:C,C2) is converted into DAX as follows.
Create a measure in your Power BI model.Measure = CALCULATE ( SUM ( Table[D] ), FILTER ( Table, AND ( Table[A] <= Table[A2] && Table[B] = Table[B2], Table[C] = Table[C2] ) ) )
Table[A], Table[B],Table[C] and Table[D] are column in Table, while Table[A2], Table[B2] and Table[C2] are fixed value in Table. Please replace them to yours, you will get expected result.
Best Regards,
Angelia