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
rcorn
Frequent Visitor

Dynamically get top 12 time periods when switching between date field parameters

All - 

 

I am trying to show the most recent twelve date results for each selection "Year", "Quarter and Year", and "Month and Year" which are field parameters from my date table 'date'.

 

Date Table is the following:

Date =
VAR Days = CALENDAR(min(test[PIF Date]),max(test[PIF Date]))
RETURN ADDCOLUMNS (
    Days,
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "mmmm" ),
    "Month Number", MONTH([Date]),
    "Start of the Month", DATE( YEAR([Date]), MONTH([Date]),1),
    "End of the Month", EOMONTH([Date],0),
    "Quarter and Year", "Q"&FORMAT([Date],"Q YYYY"),
    "Month and Year", FORMAT([Date],"MMM YYYY")
)
 
Graphs show volume by field parameter dates. 
Volume calculation = 
Volume = CALCULATE(SUM(test[Volume]), USERELATIONSHIP(test[Date],'Date'[Date]))

rcorn_2-1664379749028.png

rcorn_3-1664379760195.png

 

 

Do I need to write a new measure for Volume that only pulls top 12 most recent date periods?  In the Quarter and Year instance I only want to show Q1-Q4 for 2020 - 2022 volume. How do I write this?

 

 

5 REPLIES 5
jcalheir
Solution Supplier
Solution Supplier

Hi

 

Yes, you can create a measure that checks which data format is in scope and then filter the 12 most recent dates.

Something like this:

 

Volume Last 12 Periods = 

RETURN
    SWITCH (
        TRUE (),
        ISINSCOPE ( Date[Year] ), 
            CALCULATE(
                [Volume],
				DATESINPERIOD(
					'Date'[Date],
					MAX('Date'[Date]),
					-12,
					YEAR
				)
    )

            ),
        ISINSCOPE ( Date[Quarter] ) && ISINSCOPE ( Date[Year] ), 
            CALCULATE(
                [Volume],
				DATESINPERIOD(
					'Date'[Date],
					MAX('Date'[Date]),
					-12,
					QUARTER
				)
    ),
    ISINSCOPE ( Date[Month] ) && ISINSCOPE ( Date[Year] ), 
            CALCULATE(
                [Volume],
				DATESINPERIOD(
					'Date'[Date],
					MAX('Date'[Date]),
					-12,
					MONTH
				)
    )
    )


 

 

Kind regards,
José
Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂 

This did not work, it did not get rid of dates prior to the most recent 12 time periods and sum of the volume was inaccurate.

jcalheir
Solution Supplier
Solution Supplier

Would you mind sharing a pbix file with some sample data?

I want bottom right graph to look like other three when you switch between dates. (top 12 for each)

rcorn_0-1664460287002.png

 

 

All I have for my fact table columns is uniuqe ID, volume amount, volume date.

 

I show DAX for data table, volume, and field parameters below.

 

My date table :

Date Table is the following:

Date =
VAR Days = CALENDAR(min(test[PIF Date]),max(test[PIF Date]))
RETURN ADDCOLUMNS (
    Days,
    "Year"YEAR ( [Date] ),
    "Month"FORMAT ( [Date], "mmmm" ),
    "Month Number"MONTH([Date]),
    "Start of the Month"DATEYEAR([Date]), MONTH([Date]),1),
    "End of the Month"EOMONTH([Date],0),
    "Quarter and Year""Q"&FORMAT([Date],"Q YYYY"),
    "Month and Year"FORMAT([Date],"MMM YYYY")
)
 
My volume calculation is : 
Volume = CALCULATE(SUM(test[Volume]), USERELATIONSHIP(test[Date],'Date'[Date]))
 
Field parameter: 
Parameter = {
    ("Year", NAMEOF('Date'[Year]), 0),
    ("Quarter and Year", NAMEOF('Date'[Quarter and Year]), 1),
    ("Month and Year", NAMEOF('Date'[Month and Year]), 2)
}

I am not certain about how to share, there is no choose file option on the reply.

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.