Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
ramshoney1225
Helper V
Helper V

Need DAX Correction - to display upto selected months

Hi 

 

I have created few DAXs and it was working fine, but i got change in the requriment which i'm not able to do

 

Old Requirement when selected Year = 2021, Month = March as slicer values then my graph shows as below 

ramshoney1225_0-1642590238850.png

1.) Bar measure show selected Month

2.) Line measure show all the months 

 

I have 4 Bar measures, I have 4 line measures for reference im sharing of one line measure which i'm having issue in line measure.

 

Line measure DAX created as below 

 

Line Measure =
var _tab=ALL('Sheet1'[Month])
var _tab1=ALLSELECTED('Sheet1'[Year])
RETURN
CALCULATE(SUM('Sheet1'[ActualData]),
FILTER(('Sheet1'),
'Sheet1'[month] in _tab &&
'Sheet1'[Year] in _tab1
))

 

Now new requirement, when selected Year = 2021, Month = March as slicer values then it should show as below 

1.) Bar measure Should show selected Month ( Same as old Requirment)

2.) Line measure Should show upto selected Month ( New Requirment )

 

so how to alter or modify existing logic for line measure please help

 

Please find the below sample data for understanding columns ( I have Year, MonthNum, Month )

 

YearMonthNumMonthActualDataActualTarget
20214April111.72113
20215May106.54113
20214April118.07113
20215May117.65113
20214April115.1113
20215May83.86113
20214April118.52113
20215May104.5113
20214April105.83113
20215May93.06113
20214April119.56113
20215May118.85113
20214April119.8113
20215May60113

 

 

Thanks,

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @ramshoney1225 ,

According to your description, you have a slicer of month column, and the axis of the chart is also month, then when you select a value in the slicer, how can not the chart axis be filtered. 

My solution is create another new table.

vkalyjmsft_0-1643018160062.png

Table = SUMMARIZE('Sheet1','Sheet1'[Month],'Sheet1'[MonthNum])

The formula of Line Measure is:

Line Measure =
VAR _tab =
    ALLSELECTED ( 'Sheet1'[Year] )
RETURN
    CALCULATE (
        SUM ( 'Sheet1'[ActualData] ),
        FILTER (
            ( 'Sheet1' ),
            'Sheet1'[MonthNum] <= SELECTEDVALUE ( 'Table'[MonthNum] )
                && 'Sheet1'[Year] IN _tab
        )
    )

Then put the Month column in the new table in a slicer, the original month column in the chart axis, the Line measure will show upto selected Month. 

vkalyjmsft_1-1643018459352.png

vkalyjmsft_2-1643018464384.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @ramshoney1225 ,

According to your description, you have a slicer of month column, and the axis of the chart is also month, then when you select a value in the slicer, how can not the chart axis be filtered. 

My solution is create another new table.

vkalyjmsft_0-1643018160062.png

Table = SUMMARIZE('Sheet1','Sheet1'[Month],'Sheet1'[MonthNum])

The formula of Line Measure is:

Line Measure =
VAR _tab =
    ALLSELECTED ( 'Sheet1'[Year] )
RETURN
    CALCULATE (
        SUM ( 'Sheet1'[ActualData] ),
        FILTER (
            ( 'Sheet1' ),
            'Sheet1'[MonthNum] <= SELECTEDVALUE ( 'Table'[MonthNum] )
                && 'Sheet1'[Year] IN _tab
        )
    )

Then put the Month column in the new table in a slicer, the original month column in the chart axis, the Line measure will show upto selected Month. 

vkalyjmsft_1-1643018459352.png

vkalyjmsft_2-1643018464384.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@ramshoney1225 , best is that you use before date range slicer. Other wise you need an independent date table for slicer

 

You need one or more measures like

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])5
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] <=_max))

 

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.