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.
Hi Everyone,
we have a date dimension and sales fact table. we have to display sales by week.
dropdown slicer: week(feb 4 - feb 10).
when we display sales, if the selected week does not have sales, we should consider the previous week, till the week which is having the sales.
How do we do that using DAX?
Solved! Go to Solution.
Kindly mark the answer as a solution to close this thread.
Regards,
Cherie
are you able to post a dastaset sample?
thanks
Did I answer your question correctly? Mark my answer as a solution!
Proud to be a Datanaut!
You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.
Regards,
Cherie
Hi @LivioLanzo and @v-cherch-msft
plz find the sample dataset and pbix files.
https://github.com/bodempudi/CodeSnippets/blob/master/PowerBI/Demos/DataSet.xlsx
https://github.com/bodempudi/CodeSnippets/blob/master/PowerBI/Demos/sample_pbix_file.pbix
i have the PBIX file too, please select the week date range and see the stacked chart. when we have sales for a particular week, we should consider the previous week, which is having sales.
Thanks..
You may try below measure.Attached the file for your reference.
Measure = VAR LastWeek_notnullsales = IF ( [SUM_Sales] = BLANK (), MAXX ( FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] < MAX ( Dimdate[WeekOfYear] ) ), [WeekIndex] ), MAX ( Dimdate[WeekOfYear] ) ) RETURN CALCULATE ( [SUM_Sales], FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] = LastWeek_notnullsales ) )
Regards,
Cherie
it is not working when user selects multiple weeks.
in our example, if users selects Feb 17-Feb 23 and Feb 24 - Feb 28. it should display Feb 17- Feb 23.
It is not working, it is displaying blank report.
Thanks..
after modifying the expression as below it is working fine..
Measure =
var week=max(Dimdate[WeekOfYear])
VAR LastWeek_notnullsales =
IF (
(CALCULATE([SUM_Sales],Dimdate[WeekOfYear]=week) = BLANK ()),
MAXX (
FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] < MAX ( Dimdate[WeekOfYear] ) ),
[WeekIndex]
),
MAX ( Dimdate[WeekOfYear] )
)
RETURN
CALCULATE (
[SUM_Sales],
FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] = LastWeek_notnullsales )
)
Kindly mark the answer as a solution to close this thread.
Regards,
Cherie
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
100 | |
75 | |
73 | |
49 |
User | Count |
---|---|
145 | |
109 | |
109 | |
90 | |
64 |