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
jcollins_IFM
Regular Visitor

Measure - current and past month totals based on slicer selection

Hoping this isn't too basic a question, but after a couple of days of unsuccessfully trying to modify solutions to 'similar' situations online I thought it might be time to ask the question directly. 

 

I am trying to calculate current and past month values, based on the year and month the user has selected in a slicer, the slicer values are based on the Month and Year values from 'ReportingPeriod' column in the sample below

 

SourceIDReportingPeriod
S11/12/2020
S21/12/2020
S31/12/2020
S41/12/2020
S51/12/2020
S61/12/2020
S11/01/2021
S21/01/2021
S11/01/2021
S31/01/2021
S41/01/2021
S11/02/2021
S21/02/2021
S31/02/2021
S41/02/2021
S51/02/2021

 

I would like to create a couple of measures which will show a distinct count of the 'sourceID' values for both the current month and the previous month based on the month and year selected in the slicer. 

 

If the user selected February 2021 in the slicer, then the value for the current month should be 5 and the value for the previous month should be 4. If the user selected January 2021 in the slicer, then the value for the current month should be 4 and the value for the previous month should be 6. 

 

The main issue I'm having is that the slicer appears to be filtering out all data aside from the selected month / year, so when I try to create a 'Previous Year' calculation it comes up blank. I've removed the interaction between the slicer and the visual I want to use for Prev Month but now the criteria is too loose, using the example above the previous month calculation returns 6 regardless of the slicer selection because that's the total number of distinct values in the sourceID column across all reporting dates. 

 

Hopefully that's enough information to get started, but if more is required I'll be happy to provide...

 

Regards, 

Jason

 

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

Hi @jcollins_IFM 

You can create a calendar date table as a slicer to filter the data in your data table .

(1)Create a calendar date table and a column with “Year-Month” format .

Calendar Date = CALENDAR(DATE(2020,01,01),DATE(2021,12,31))
Year Month = YEAR('Calendar Date'[Date]) & "-" & MONTH('Calendar Date'[Date])

(2)Create a one to many relationship between calendar table and data table .

Ailsamsft_0-1627019101526.png

(3)Create a slicer with the field 'Calendar Date'[Year Month] to filter data .

(4)Create measures to count the numbers of 'Table'[SourceID] .

current month count = DISTINCTCOUNT('Table'[SourceID])
previous month count = CALCULATE(DISTINCTCOUNT('Table'[SourceID]),PREVIOUSMONTH('Calendar Date'[Date]))

The final result is as shown :

Ailsamsft_1-1627019101528.pngAilsamsft_2-1627019101530.png

I have attached my pbix file , you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

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-yetao1-msft
Community Support
Community Support

Hi @jcollins_IFM 

You can create a calendar date table as a slicer to filter the data in your data table .

(1)Create a calendar date table and a column with “Year-Month” format .

Calendar Date = CALENDAR(DATE(2020,01,01),DATE(2021,12,31))
Year Month = YEAR('Calendar Date'[Date]) & "-" & MONTH('Calendar Date'[Date])

(2)Create a one to many relationship between calendar table and data table .

Ailsamsft_0-1627019101526.png

(3)Create a slicer with the field 'Calendar Date'[Year Month] to filter data .

(4)Create measures to count the numbers of 'Table'[SourceID] .

current month count = DISTINCTCOUNT('Table'[SourceID])
previous month count = CALCULATE(DISTINCTCOUNT('Table'[SourceID]),PREVIOUSMONTH('Calendar Date'[Date]))

The final result is as shown :

Ailsamsft_1-1627019101528.pngAilsamsft_2-1627019101530.png

I have attached my pbix file , you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

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

DataInsights
Super User
Super User

@jcollins_IFM,

 

This solution requires a date table that has a relationship with the data table. Be sure to use DimDate[Month Year] in the date slicer. Time intelligence calculations work best with a date table.

 

DataInsights_0-1626993842404.png

 

Measures:

 

Count SourceID = DISTINCTCOUNT ( Table1[SourceID] )

Count SourceID Previous Month = CALCULATE ( [Count SourceID], PREVIOUSMONTH(DimDate[Date] ) )

 

DataInsights_1-1626993881940.png

---------------------------------------------------

DataInsights_2-1626993902289.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.