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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
abhay03
Helper I
Helper I

Calculate previous date from Slicer value

In the following table, there is a filter on Date column: 

 

DateProductsUnits
8/5/2017A10
8/5/2017B5
8/6/2017A25
8/6/2017B15
8/7/2017A30
8/7/2017B20

 

I want if no value is selected for Date in slicer then show the product wise comparison for maximum date and previous day. If a value is selected in slicer then show the comparison for the selected day and its previous day. If the minimum date value is selected then show details only for selected Date.

 

I want to create a matrix visual with expected output for Date for 8/7/2017 (or no filter selected, since this is a maximum date):

ProductsUnitsTotal
Date8/7/20178/6/2017 
A302555
B201535
Total504090

 

I tried creating the DAX expression below but in the visual, no data is displaying if any of the filters is selected.

Previous Day Count = CALCULATE(SUM(Dataset[Units]), FILTER(Dataset, Dataset[Date] = IF (ISFILTERED(Dataset[Date]) && HASONEVALUE(Dataset[Date]), FIRSTDATE(Dataset[Date])-1, MAX(Dataset[Date])-1)))
1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee


@abhay03 wrote:

In the following table, there is a filter on Date column: 

 

Date Products Units
8/5/2017 A 10
8/5/2017 B 5
8/6/2017 A 25
8/6/2017 B 15
8/7/2017 A 30
8/7/2017 B 20

 

I want if no value is selected for Date in slicer then show the product wise comparison for maximum date and previous day. If a value is selected in slicer then show the comparison for the selected day and its previous day. If the minimum date value is selected then show details only for selected Date.

 

I want to create a matrix visual with expected output for Date for 8/7/2017 (or no filter selected, since this is a maximum date):

Products Units Total
Date 8/7/2017 8/6/2017  
A 30 25 55
B 20 15 35
Total 50 40 90

 

I tried creating the DAX expression below but in the visual, no data is displaying if any of the filters is selected.

Previous Day Count = CALCULATE(SUM(Dataset[Units]), FILTER(Dataset, Dataset[Date] = IF (ISFILTERED(Dataset[Date]) && HASONEVALUE(Dataset[Date]), FIRSTDATE(Dataset[Date])-1, MAX(Dataset[Date])-1)))

@abhay03

Try to create a calendar table and a measure as below. See more details in the attached pbix.

 

Calendar =
CALENDAR ( MIN ( Table1[Date] ), MAX ( Table1[Date] ) )

SumUnit =
IF (
    MAX ( Table1[Date] )
        = MAXX ( ALLSELECTED ( Calendar[Date] ), Calendar[Date] ) - 1
        || MAX ( Table1[Date] ) = MAXX ( ALLSELECTED ( Calendar[Date] ), Calendar[Date] ),
    SUM ( Table1[Units] ),
    BLANK ()
)

Capture.PNG

 

View solution in original post

1 REPLY 1
Eric_Zhang
Microsoft Employee
Microsoft Employee


@abhay03 wrote:

In the following table, there is a filter on Date column: 

 

Date Products Units
8/5/2017 A 10
8/5/2017 B 5
8/6/2017 A 25
8/6/2017 B 15
8/7/2017 A 30
8/7/2017 B 20

 

I want if no value is selected for Date in slicer then show the product wise comparison for maximum date and previous day. If a value is selected in slicer then show the comparison for the selected day and its previous day. If the minimum date value is selected then show details only for selected Date.

 

I want to create a matrix visual with expected output for Date for 8/7/2017 (or no filter selected, since this is a maximum date):

Products Units Total
Date 8/7/2017 8/6/2017  
A 30 25 55
B 20 15 35
Total 50 40 90

 

I tried creating the DAX expression below but in the visual, no data is displaying if any of the filters is selected.

Previous Day Count = CALCULATE(SUM(Dataset[Units]), FILTER(Dataset, Dataset[Date] = IF (ISFILTERED(Dataset[Date]) && HASONEVALUE(Dataset[Date]), FIRSTDATE(Dataset[Date])-1, MAX(Dataset[Date])-1)))

@abhay03

Try to create a calendar table and a measure as below. See more details in the attached pbix.

 

Calendar =
CALENDAR ( MIN ( Table1[Date] ), MAX ( Table1[Date] ) )

SumUnit =
IF (
    MAX ( Table1[Date] )
        = MAXX ( ALLSELECTED ( Calendar[Date] ), Calendar[Date] ) - 1
        || MAX ( Table1[Date] ) = MAXX ( ALLSELECTED ( Calendar[Date] ), Calendar[Date] ),
    SUM ( Table1[Units] ),
    BLANK ()
)

Capture.PNG

 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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