Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
dhenders1833
Frequent Visitor

MTD/QTD/YTD Slicer With YOY Comparison Table/Matrix- Yielding Blanks

I am trying to construct a table or matrix that will show current year and prior year utilzing a MTD/QTD/YTD/Custom slicer.  The issue is that PY pulls in when custom is selected, however when MTD/QTD/YTD are selected it yields blanks.  I am hoping someone help me identify the issue as I am stumped!

 

Here my tables and relationship connections:

dhenders1833_1-1716063223398.png

tbl_ReportData: fact table
tbl_Slicer: disconnected table with MTD, QTD, YTD, and Custom periods along with order
tbl_Date = CALENDAR(MIN(tbl_ReportData[Date]),MAX(tbl_ReportData[Date]))
tbl_DatePeriods =
UNION(
ADDCOLUMNS(
    DATESMTD(tbl_Date[Date]),
        "Type","MTD",
        "Order", 1
),
ADDCOLUMNS(
    DATESQTD(tbl_Date[Date]),
    "Type","QTD",
    "Order", 2
   
),
ADDCOLUMNS(
    DATESYTD(tbl_Date[Date]),
    "Type","YTD",
    "Order",3  
),
ADDCOLUMNS(
    CALENDAR(MIN(tbl_Date[Date]),MAX(tbl_Date[Date])),
    "Type","Custom",
    "Order",5    
    )
)
 
I made sure that "Both" is selected as the cross-filter direction between the tbl_Date and tbl_DatePeriods.  I also made sure tbl_Date is marked as a date table.
 
The measure I am using for PY is: 
PY Revenue = CALCULATE([Total Revenue],DATEADD(tbl_Date[Date],-1,YEAR)).
 
I have also tried PARALLEYEAR and SAMEPERIODASLASTYEAR and neither seem to work.
1 ACCEPTED SOLUTION

I went back to review the example you provided have determined there are two issues: 1) there was a relationship issue between the tables.  Your example helped identify that, so that was a partial solution.  2) there is an issue when using the DATEADD function with a dataset that does not have consistent periods.  The set is comprised of sales by store, however there are new stores where there are not records from the prior year available.  For some reason, this causes the function to not work.  I will start a separate thread, as I am still perplexed by this piece.  I used PARALLELPERIOD instead and this in conjuction with the relationship changes seemed to work.  Thank you!

View solution in original post

7 REPLIES 7
DataNinja777
Super User
Super User

Hi @dhenders1833 

There are many ways to achieve your required output and by using the disconnected table of the MTD, QTD, and YTD scenarios, you are on right track.  I tried to recreate your solution by copying and pasting the dax formula you've created, and I wasn't too sure what was the purpose of having tbl_DatePeriods in the data model.  

There seems to be simlpler ways to accomplish your task, and one of them is as follows:

1. Create a slicer table and set it as a disconnected table in your data model.  You can use database dax function but I just typed directly in grid in power query as it take as long as to write the formula.  

DataNinja777_0-1716099986950.png

2) Create a selected measure formula linking the slicer table selection with the MTD, QTD and YTD measures.  I am assuming that you have already created MTD, QTD and YTD measures using the standard dax time intelligence functions prior to writing this selected measure formula.

DataNinja777_1-1716100140485.png3) Then, use another standard dax time intelligence function like selectedperiodlast year in conjunction with the [Selected Measure] formula to create the measure for the comparative figures for the selected scenarios.  

DataNinja777_2-1716100258681.png

The resultant visualization is as follows where the [Selected Measure] and [Sameperiodlastyear for selected measure] is flexibly switched according to your choice in the slicer.  

DataNinja777_0-1716100722365.png

 

I attach an example pbix file with the dummy data I created on the fly.  

Best regards,

 

Thank you for the reply.  I tried following the steps that you provided, however the issue seems to still persist.   I am able to calculate PY when custom is selected, however whenever I select MTD/QTD/YTD, it returns a blank.  I believe it could have to do with the custom filter I have included, and/or with the possibility that there is not a prior year date for every current year date.  Any thoughts on a workaround?

 

When custom filter is selected:

dhenders1833_0-1716212168408.png

When YTD is selected:

dhenders1833_1-1716212209722.png

 

Hi @dhenders1833 ,

 

I am assuming that you have created a calculated calendar table and created a relationship between the date field in your fact table (many side of the relationship) and calendar table date field (one side of the relationship) to take advantage of the dax time intelligence functions.  Please confirm this point, just in case. 

Best regards,

 

I went back to review the example you provided have determined there are two issues: 1) there was a relationship issue between the tables.  Your example helped identify that, so that was a partial solution.  2) there is an issue when using the DATEADD function with a dataset that does not have consistent periods.  The set is comprised of sales by store, however there are new stores where there are not records from the prior year available.  For some reason, this causes the function to not work.  I will start a separate thread, as I am still perplexed by this piece.  I used PARALLELPERIOD instead and this in conjuction with the relationship changes seemed to work.  Thank you!

Correct.  Please see below:

dhenders1833_0-1716213387347.png

 

xifeng_L
Super User
Super User

What is the expression of the measure you are using in the matrix?

The expression is: 

PY Revenue =
CALCULATE(
    [Selected Measure],
    SAMEPERIODLASTYEAR(tbl_Date[Date])
)
 
Where selected measure = 
Selected Measure = switch(min(tbl_Slicer[Order_By]),1,[MTD sales],2,[QTD sales],3,[YTD sales],4,[Total Revenue])

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.