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
semidevil
Helper I
Helper I

how to dynamically retrieve previous months data

I have my data set more or less structured in the following where I have these columns:

A datetime column (date format)

a yearMonth(i,e YYYYMM) column (number format)

value column (number format).

 

I need to create a bar graph where with 3 bars:

a 2016 bar that sums up the value at 201612 (never change)

a 2017 bar that sums up the value at 201712 (never change)

a 2018 bar that will always sum the previous months values  So in February 2018, it will sum up the value of Jan 2018

 

right now, I created an additional column that has a "TRUE" indicator if YYYYMM = (201612 or 201712), and I can use that as a filter....but I dont know how to make the 2018 bar "dynamic". 

 

I thought about creating yet another "PreviousMonth" column that looks outputs the current YearMonth as a number format, roll that back one month, and if (YYYMM = "PreviousMonth", TRUE, FALSE), but I dont know how to make that work.

 

How would I go about doing this?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Why not a measure like:

 

2018 = CALCULATE(SUM(Table[Value]),FILTER(Table,[yearMonth] > 201800 && [yearMonth] < MAX(Table[yearMonth)-1))

Something like that.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

Why not a measure like:

 

2018 = CALCULATE(SUM(Table[Value]),FILTER(Table,[yearMonth] > 201800 && [yearMonth] < MAX(Table[yearMonth)-1))

Something like that.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.