The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi Experts,
I want to create a dax to display the last 3 months when we select any month from the slicer. if not selected then it will display all month data in clustered column chart.
Monthname is a slicer (MonthName = FORMAT([Date],"MMMM")) //text type
Monthyear is a X axis in visual (MonthYear = FORMAT([Date], "MMM-yyyy")) //text type
Tried this measure but no luck:
Please help me on this.
Thanks
DK
Hi @DineshArivu,
Have you had a chance to review the solution we shared by @Jihwan_Kim? If the issue persists, feel free to reply so we can help further.
Thank you.
Hi,
I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
One of ways is to create calculation group, and then put the calculation item into the visual level filter pane.
Create calculation groups in Power BI - Power BI | Microsoft Learn
_cg_filter =
VAR _slicerselect =
MAX ( 'calendar slicer'[Month-Year sort] )
VAR _t =
FILTER (
ALL ( 'calendar'[Month-Year], 'calendar'[Month-Year sort] ),
'calendar'[Month-Year sort] <= _slicerselect
)
VAR _window =
WINDOW ( 1, ABS, 3, ABS, _t, ORDERBY ( 'calendar'[Month-Year sort], DESC ) )
RETURN
SWITCH (
TRUE (),
NOT ISFILTERED ( 'calendar slicer'[Month name] ), SELECTEDMEASURE (),
ISFILTERED ( 'calendar slicer'[Month name] ), CALCULATE ( SELECTEDMEASURE (), KEEPFILTERS ( _window ) ),
SELECTEDMEASURE ()
)
@Jihwan_Kim thanks for your solution.
few points from my side:
1. We are not using any columns directly like sales,values for the visual X axis (all 5 measures used)
2. as we are using measures, there is no relationship created.
3. I cannot able to apply your measure into visual filter , like the filtering type is different (is,not equals,is blank,no blank).
If i use the same dax as calculated column, then it prompts error
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
27 | |
19 | |
13 | |
9 | |
5 |