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
ghosh_kavitha
Helper IV
Helper IV

Calculate Previous month and next month from the selected month in the slicer

Hi,

Can some one help me to create the measure for Previous month and next month from the selected month in the slicer.

 

Thanks 

Kg

1 ACCEPTED SOLUTION

Hi @ghosh_kavitha ,

 

Please try to unpoivt your table and group your table by month and add index column:

Capture.PNG

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY27EQBBCEJ7Id7gcN371OLYfxsnBgYyIswzAhcWrOaroQxd8upM5Aqw1j2pHM9UrCsC+KRyvCWC2u6KCGfS5j1K+78j8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [JanHours = _t, FebHours = _t, MarHours = _t, AprHours = _t, MayHours = _t, JuneHours = _t, JulyHours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"JanHours", Int64.Type}, {"FebHours", Int64.Type}, {"MarHours", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Columns",{{"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Attribute"}, {{"value", each List.Sum([Value]), type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1)
in
    #"Added Index"

 

 

 

Create a measure and use index column to show the values for previous month and next month from the selected month(others are blank).

 

Would you please inform us more detailed information( your  data(by OneDrive for Business)) if possible? Then we will help you more correctly.

 

Best Regards,

Dedmon Dai

View solution in original post

6 REPLIES 6
v-deddai1-msft
Community Support
Community Support

Hi @ghosh_kavitha ,

 

The time intelligence function presupposes a complete calendar table. You can follow the link provided by amitchandak to create calendar table. Then use  NEXTMONTH and PREVIOUSMONTH function.

 

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

 

Best Regards,

Dedmon Dai

 

Hi, Actually this is my table. i have to show the dynamic 3 months(previous current next) data in the graph.Thanks Kg

ghosh_kavitha_0-1594127494593.png

 

ghosh_kavitha_0-1594285014284.png

 

Hi @ghosh_kavitha ,

 

Please try to unpoivt your table and group your table by month and add index column:

Capture.PNG

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY27EQBBCEJ7Id7gcN371OLYfxsnBgYyIswzAhcWrOaroQxd8upM5Aqw1j2pHM9UrCsC+KRyvCWC2u6KCGfS5j1K+78j8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [JanHours = _t, FebHours = _t, MarHours = _t, AprHours = _t, MayHours = _t, JuneHours = _t, JulyHours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"JanHours", Int64.Type}, {"FebHours", Int64.Type}, {"MarHours", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Columns",{{"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Attribute"}, {{"value", each List.Sum([Value]), type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1)
in
    #"Added Index"

 

 

 

Create a measure and use index column to show the values for previous month and next month from the selected month(others are blank).

 

Would you please inform us more detailed information( your  data(by OneDrive for Business)) if possible? Then we will help you more correctly.

 

Best Regards,

Dedmon Dai

amitchandak
Super User
Super User

@ghosh_kavitha , You can use time intelligence with calendar table

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
next month Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

@ghosh_kavitha ,

Use the below DAX:

Prev Month = DATEADD(Table[DateColumn],-1,MONTH)

Prev Month = PARALLELPERIOD(Table[DateColumn],-1,MONTH)

Prev Month = MONTH(MAX(Table[DateColumn]))-1

Likewise, for Next month just replace minus sign with plus sign.

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

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.