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.
Hello,
I have a column with number of customers of the day, i need to compare it with the same day last month, the problem is that i don't have all days in my table, i don't have weekends and holidays, because there are no customers these days. For these days i need to find the closest day.
Ex:
day 23/03/2023 (717) i want to compare with 23/02/2023 (817)
day 22/03/2023 (773) i want to compare with 17/02/2023 (758), because I don't have 22/02/2023 so the next available day is 17/02
Thanks
Solved! Go to Solution.
Hi,
I assume you have a date dim table in the model.
Please check the below picture and the attached pbix file. I tired to create a sample pbix file like below.
I hope the below can provide some ideas on how to create a solution for your datamodel.
Prev month value measure: =
VAR _prevmonthdate =
CALCULATE ( MAX ( 'Calendar'[Date] ), DATEADD ( 'Calendar'[Date], -1, MONTH ) )
VAR _alldatesbeforeprevmonthdate =
ADDCOLUMNS (
FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] <= _prevmonthdate ),
"@value", [Value measure:]
)
VAR _nonblankvaluelatestdatebeforeprevmonthdate =
MAXX (
FILTER ( _alldatesbeforeprevmonthdate, [@value] <> BLANK () ),
'Calendar'[Date]
)
RETURN
IF (
NOT ISBLANK ( [Value measure:] ),
CALCULATE (
[Value measure:],
'Calendar'[Date] = _nonblankvaluelatestdatebeforeprevmonthdate
)
)
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Hi,
I assume you have a date dim table in the model.
Please check the below picture and the attached pbix file. I tired to create a sample pbix file like below.
I hope the below can provide some ideas on how to create a solution for your datamodel.
Prev month value measure: =
VAR _prevmonthdate =
CALCULATE ( MAX ( 'Calendar'[Date] ), DATEADD ( 'Calendar'[Date], -1, MONTH ) )
VAR _alldatesbeforeprevmonthdate =
ADDCOLUMNS (
FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] <= _prevmonthdate ),
"@value", [Value measure:]
)
VAR _nonblankvaluelatestdatebeforeprevmonthdate =
MAXX (
FILTER ( _alldatesbeforeprevmonthdate, [@value] <> BLANK () ),
'Calendar'[Date]
)
RETURN
IF (
NOT ISBLANK ( [Value measure:] ),
CALCULATE (
[Value measure:],
'Calendar'[Date] = _nonblankvaluelatestdatebeforeprevmonthdate
)
)
Works like a Charm Thanks, I'll study this formula to understand in the future, Thank you, my friend
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
12 | |
10 | |
6 |