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
Anonymous
Not applicable

Show previous months values for a selected month(I have months and Years in a specific order)

Hello All, 

I have situation where I have to show previous months data in line graph based on month selection in slicer

My table

fiscal year

MonthYearValue_1Value_2Value_3Value_4
2020July201915245432
2020August20195356524
2020September201965698798
2020October20197879678
2020November2019256252458
2020December20193596546354
2020January202024582555465
2020February2020236352532
2020March2020253023712
2020April2020263363214
2020May20206303702718
2020June202068240423100
2021July20207344381820
2021August20207864731358
2021September2020837507869
2021October2020889541375
2021November20209415753595
2021December20209936096935
2021January202110456438715
2021February202110976782572
2021March2021114871265482
2021April202112007462559
2021May20211252780355
2021June2021130481430086

Now I have a slicer for Fiscal Year and Month

slicer

Fiscal Year I have 2020 and 2021(lets say we select 2020)

Month: July 2019 to June 2020(the months are in order July to June)

 

 

Now If I select July in the month Slicer then i have to show only July Month values 

fiscal yearMonthYearValue_1Value_2Value_3Value_4
2020July201915245432

 

Now If I select January  in the month Slicer then i have to show July values to January  

2020July201915245432
2020August20195356524
2020September201965698798
2020October20197879678
2020November2019256252458
2020December20193596546354
2020January202024582555465

 

Can anyone help me with this situation

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Please follow the below steps to achieve it:

1. Create a fiscal year months table as below

fiscal year table.JPG

2. Create a calculated column to get the fiscal month order

Nmonthorder = CALCULATE(MAX('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month]='Table'[Month]))

create calculated column to get fiscal month order.JPG

3. Create 4 measures as below to get the the corresponding value_1, value_2, value_3 and value_4 in previous selected month

Nvalue_1 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_1]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 
Nvalue_2 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_2]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 
Nvalue_3 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_3]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 
Nvalue_4 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_4]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 

4. Drag the month field in new created fiscal year months table onto the slicer to replace the original month slicer, and put the new created 4 measures to replace the original values fields on table visual

desired result.JPG

I just create sample report file, you can get it from this link and check all of above information.

Best Regards

Rena

Community Support Team _ Rena
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

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

Please follow the below steps to achieve it as workaround:

1. Create a calculated column YearMonth

YearMonth = 
VALUE (
    CONCATENATE (
        'Table'[Year],
        SWITCH (
            'Table'[Month],
            "January", "01",  "February", "02", "March", "03", "April", "04","May", "05","June", "06",
            "July", "07","August", "08", "September", "09","October", "10","November", "11","December", "12"
        )
    )
)

2. Apply this calculated column on slicer to replace the original month slicer

previous months.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

but my requirement for this project is that i must show the months in the slicer  

I cant replace the months with year month number

Hi @Anonymous ,

Please follow the below steps to achieve it:

1. Create a fiscal year months table as below

fiscal year table.JPG

2. Create a calculated column to get the fiscal month order

Nmonthorder = CALCULATE(MAX('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month]='Table'[Month]))

create calculated column to get fiscal month order.JPG

3. Create 4 measures as below to get the the corresponding value_1, value_2, value_3 and value_4 in previous selected month

Nvalue_1 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_1]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 
Nvalue_2 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_2]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 
Nvalue_3 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_3]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 
Nvalue_4 = var _sfMonth = SELECTEDVALUE('Fiscal year'[Fiscal Month])
var sfmonthOrder = CALCULATE(SUM('Fiscal year'[Order]),FILTER('Fiscal year','Fiscal year'[Fiscal Month] = _sfMonth))
return CALCULATE(SUM('Table'[Value_4]),FILTER('Table','Table'[Nmonthorder]<=sfmonthOrder)) 

4. Drag the month field in new created fiscal year months table onto the slicer to replace the original month slicer, and put the new created 4 measures to replace the original values fields on table visual

desired result.JPG

I just create sample report file, you can get it from this link and check all of above information.

Best Regards

Rena

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

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.