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
Anonymous
Not applicable

How to use slicer for faster filtering with date columns and periods

It sounds easy but after reading serveral posts I am breaking my head on this one.

The data is as follows

 

Order_IDOrder_dateOrder_shipped
127-12-20207-1-2021
231-12-20208-1-2021
31-1-202124-3-2012
42-1-202124-3-2012
53-1-20213-1-2021
64-1-202118-2-2021
75-1-202116-2-2021
86-1-202115-1-2021
97-1-202114-3-2021
1010-1-202131-1-2021
1111-1-202131-1-2021
1220-2-202114-3-2021
1320-2-2021NULL

When the value is null/empty it means it not shipped.

 

As you might can imagine it can be nice to know what happend in a period.

In this example the period is 1 January 2021 until 15 January 2021.

For this I created  a few graphs as explained below.

 

GRAPH A Open orders at the begin of period FORMULA Order shipped > 1-1-2021 OR IS NOT FILLED AND Order date < 1-1-2021


GRAPH B Open orders at the end of period FORMULA Order shipped < 15-1-2021 AND Order date <15-1-2021

 

GRAPH C Orders shipped in period FORMULA Order shipped 1-1-2021 <> 1-15-2021

 

GRAPH D New orders in period FORMULA Order date 1-1-2021 <> 1-15-2021

 

All working as expected. The only thing the filter needs to be defined manually at the moment for every graph.

It would be nice if the period could be selected one time and all the data in the graphs adjusts

 

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

Hi, @Anonymous ;

You could create a calendar table as a slicer date. then create four meausres for 4 GRAPHs , as follows:

1.create a calendar table.

slicer = CALENDAR(DATE(2020,12,27),DATE(2021,3,14))

2.create four flag measures:

flagA = IF((MAX([Order_shipped])>MIN('slicer'[Date])||MAX([Order_shipped])=BLANK())&&MAX([Order_date])<MIN('slicer'[Date]),1,0)
flagB = IF(MAX([Order_shipped])<MAX('slicer'[Date])&&MAX([Order_date])<MAX('slicer'[Date]),1,0)
flagC = IF(MAX([Order_shipped])<=MAX('slicer'[Date])&&MAX([Order_shipped])>=MIN('slicer'[Date]),1,0)
flagD = IF(MAX([Order_date])<=MAX('slicer'[Date])&&MAX([Order_date])>=MIN('slicer'[Date]),1,0)

3.Four measures were applied to the filter of each GRAPHs.

vyalanwumsft_0-1628495099186.pngvyalanwumsft_1-1628495140460.png

The final output is shown below:

vyalanwumsft_3-1628495214912.pngvyalanwumsft_4-1628495246093.png

 

Best Regards,
Community Support Team_ Yalan Wu
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

9 REPLIES 9
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create a calendar table as a slicer date. then create four meausres for 4 GRAPHs , as follows:

1.create a calendar table.

slicer = CALENDAR(DATE(2020,12,27),DATE(2021,3,14))

2.create four flag measures:

flagA = IF((MAX([Order_shipped])>MIN('slicer'[Date])||MAX([Order_shipped])=BLANK())&&MAX([Order_date])<MIN('slicer'[Date]),1,0)
flagB = IF(MAX([Order_shipped])<MAX('slicer'[Date])&&MAX([Order_date])<MAX('slicer'[Date]),1,0)
flagC = IF(MAX([Order_shipped])<=MAX('slicer'[Date])&&MAX([Order_shipped])>=MIN('slicer'[Date]),1,0)
flagD = IF(MAX([Order_date])<=MAX('slicer'[Date])&&MAX([Order_date])>=MIN('slicer'[Date]),1,0)

3.Four measures were applied to the filter of each GRAPHs.

vyalanwumsft_0-1628495099186.pngvyalanwumsft_1-1628495140460.png

The final output is shown below:

vyalanwumsft_3-1628495214912.pngvyalanwumsft_4-1628495246093.png

 

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Hey Yalun Wu,

First of all thanks for you broad answer really helped a lot. This kind of structure seems to suit the current situation.  All so adding the file helped a lot.

Flag B contained as small error from my side Order Shipped Date should be larger then 15-1-2021 to display open orders at the end of period. Further more Order Shipped Date can be blank. So I adjusted the formula to. 

 

IF(MAX([Order_shipped])> MAX('Slicer'[Date]) || MAX([Order_shipped)=BLANK()
&& MAX([Order_date])<MAX('Slicer'[Date]) ,1,0)

 

This works well only it doesnt show orders before the minimum date. Furthermore applying this if statement is kind of slow with a large amount of 20000 + records is there anyway we can do this more efficient?

Thanks in advance.

 

 

 


Anonymous
Not applicable


@Anonymous wrote:

 

 

IF(MAX([Order_shipped])> MAX('Slicer'[Date]) || MAX([Order_shipped)=BLANK()
&& MAX([Order_date])<MAX('Slicer'[Date]) ,1,0)

 

 

This works well only it doesnt show orders before the minimum date. Furthermore applying this if statement is kind of slow with a large amount of 20000 + records is there anyway we can do this more efficient?

Thanks in advance.

 

 



The first issue I resolved by removing any active relationships between the date table and the order table. The efficiency I managed to improve by defining variables for max date or min date so.

 

VAR max_date = MAX('Date'[Date])
RETURN
IF(MAX([Order_shipped])> max_date || MAX([Order_shipped)=BLANK()
&& MAX([Order_date])<max_date ,1,0)

 

 This resolved all performance issues 🙂  

Hi, @Anonymous ;

If you want to  show orders before the minimum date, you could use MIN('Slicer'[Date])
and i think maybe it's better to have a parenthesis here.

vyalanwumsft_0-1628559604248.png

Congratulations on solving the performance problem, by the way.
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks everything works now only this query keeps having performance issues due to the involving the = BLANK() parameter. Do you have any tips to work around it?
Query is as below.

 

Slicer Open order at begin date=
VAR min_date = MIN('Date'[Date])
VAR MaxOS =  MAX(Orders[Order_shipped])
VAR MaxOD = MAX(Orders[Order_date])
RETURN 
IF(MaxOD  < min_date, 
    IF( MaxOS = BLANK() || MaxOS > min_date ,1,0),0)

Hi, @Anonymous ;

Perhaps this article will be helpful for you.

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-1/ba-p/976275

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks managed so solve this to with the query below.

VAR min_date = MIN('Date'[Date])
VAR MaxOS =  MAX(Orders[Order_shipped])
VAR MaxOD = MAX(Orders[Order_date])
VAR Temp_table =
        ADDCOLUMNS(
            FILTER(
                'Orders',
                    Max(Orders[Order_date]) < min_date   
                )
            ,
            "Orders",
SWITCH(TRUE(),
Maxcompl > min_date , 1,
Maxaanml  < min_date && MaxOD = BLANK(),1))
RETURN
SUMX(Temp_table,[Orders])

 Thanks for the suggestions sometimes it is hard to find these articles yourself. In the end in the future power bi becomes more user friendly. This could be done by connecting slicers to filters. 

Mohammad_Refaei
Solution Specialist
Solution Specialist

Create relathioships to both Order_date and Order_shipped and activate them in your measures using USERELATIONSHIP

Anonymous
Not applicable

I see where youre going. But what would the measure look like then for graph A?

 

CALCULATE(COUNTROWS('Orders'),
USERELATIONSHIP( 'Orders'[Order_date], 'Orders'[Order_shipped]))

 
The starts would be something like this but then still needs to know that the order shipped date should be higher then the selected date in the slicer and the order date before the selected date in the slicer. 

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.