Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi! I am fairly new to DAX and I find it quite tricky.
I have a measure called [Amount Staging] that is (in a complex way) summing a column in my fact table: 'Booking'[Amount].
Generally, I use this measure together with two dimensions that the fact table has relationships to: 'Date' and 'Account'. I need to create a new measure that sums the [Amount Staging] results, and presents it on a certain account ('Account'[Account No]). There are two constraints for the new sum: it should only calculate the sum for [Account No]< 29000 and it should only include the selected year's entries and exclude the selected month's entries. So everything from the start of the year until (but not including) the start of the selected month.
This is how I contstructed the new measure:
VAR PriorForTheYear =
CALCULATE (
SUMX(
VALUES('Account'[Account No]),
[Amount Staging]
),
FILTER (
ALL ( 'Account' ),
VALUE('Account'[Account No]) < 29000
),
FILTER(
ALL('Date'),
'Date'[Date] > EndOfLastYear && 'Date'[Date] <= EndOfLastMonth)
)
VAR Result = IF( PLPriorForTheYearCheck, PriorForTheYear, [Amount Staging] )
RETURN RESULT
I have excluded the definition of some variables.
The issue: my result, when looking at the new measure together with 'Account'[Account No] and 'Date'[YearMonth], the new calculation sums correctly over the accounts, but only includes the [Amount Staging] for the previous month. At first I thought it was an issue with my date filter, and the EndOfLastYear in particular, but when I hardcoded it, I could see that I did get 0, when previous month was before the limit: It still did not sum all the previous months, until the lower limit.
Please let me know if you have an idea for what could be the solution here. I am currently thinking if it could be that I need to include "iteration" over 'Date', as it now possibly only iterates over the [Account No]?
*** UPDATE ***
I found a working solution: nested SUMX that iterates over Date[YearMonth] and further Account[Account No]
VAR PriorForTheYear =
CALCULATE (
SUMX(
VALUES('Date'[YearMonth]),
SUMX(
VALUES('Account'[Account No]),
[Amount Staging]
)
),
FILTER (
ALL ( 'Account' ),
VALUE('Account'[Account No]) < 29000
),
FILTER(
ALL('Date'),
'Date'[Date] > EndOfLastYear && 'Date'[Date] <= EndOfLastMonth)
)
VAR Result = IF( PLPriorForTheYearCheck, PriorForTheYear, [Amount Staging] )
RETURN Result
Hi @felicia_nc ,
Awesome! Thank you so much for taking the time to share your solution!
Best regards,
Community Support Team_ Scott Chang
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
11 | |
9 | |
6 |