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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
XavierC2
Frequent Visitor

2 slicers from same columns

Hi folks,

 

I'm facing problem that I am unable to solve by myself, I need you.

 

I have a table call_status like that

 

call_idstatusbegin_dateend_date
1open2021-06-25 13:05:222021-06-25 13:05:24
1in progress2021-06-25 13:05:242021-06-25 14:25:01
1close2021-06-25 14:25:012021-06-25 14:25:02
1archieved2021-06-25 14:25:02null

 

I need to dynamically calculate intervals between choosen status selected by 2 slicers.

 

So, I need to make 2 slicers on the same field(the second slicer should not show the value selected in the first slicer) and calculate de datediff between the begin date from the first slicer and the begin date from the second slicer.

 

thank you for your help,

 

Regards

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

Hi @XavierC2 ,

Base on before pbix file Iprovided, Try following steps:

Step1,Use the following measure ,create two begin_date:

begin_date1 =
CALCULATE (
    MAX ( 'Table'[begin_date] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[call_num] = MAX ( 'Table'[call_num] )
            && 'Table'[status] = SELECTEDVALUE ( Slicer1[status] )
    )
)
begin_date2 =
CALCULATE (
    MAX ( 'Table'[begin_date] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[call_num] = MAX ( 'Table'[call_num] )
            && 'Table'[status] = SELECTEDVALUE ( 'Slicer 2'[status] )
    )
)

Step 2, adjust before measure:

SILCERchoosedatediff = 
VAR TIME1 =
    CALCULATE (
        MAX ( 'Table'[begin_date] ),
        FILTER ( ALL ( 'Table' ), 'Table'[status] = SELECTEDVALUE ( Slicer1[status] )&&'Table'[call_num]=MAX('Table'[call_num]) )
    )
VAR TIME2 =
    CALCULATE (
        MAX ( 'Table'[begin_date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[status] = SELECTEDVALUE ( 'Slicer 2'[status] )&&'Table'[call_num]=MAX('Table'[call_num])
        )
    )
RETURN
    IF (
        TIME2 > TIME1,
        DATEDIFF ( TIME1, TIME2, MINUTE ),
        DATEDIFF ( TIME2, TIME1, MINUTE )
    )

Step 3, adjust relationship:

vluwangmsft_0-1625105040436.png

And final will get want you want!

vluwangmsft_1-1625105061512.png

 

 

Wish it is helpful for you!

 

Best Regards

Lucien

View solution in original post

8 REPLIES 8
v-luwang-msft
Community Support
Community Support

Hi @XavierC2 ,

Base on before pbix file Iprovided, Try following steps:

Step1,Use the following measure ,create two begin_date:

begin_date1 =
CALCULATE (
    MAX ( 'Table'[begin_date] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[call_num] = MAX ( 'Table'[call_num] )
            && 'Table'[status] = SELECTEDVALUE ( Slicer1[status] )
    )
)
begin_date2 =
CALCULATE (
    MAX ( 'Table'[begin_date] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[call_num] = MAX ( 'Table'[call_num] )
            && 'Table'[status] = SELECTEDVALUE ( 'Slicer 2'[status] )
    )
)

Step 2, adjust before measure:

SILCERchoosedatediff = 
VAR TIME1 =
    CALCULATE (
        MAX ( 'Table'[begin_date] ),
        FILTER ( ALL ( 'Table' ), 'Table'[status] = SELECTEDVALUE ( Slicer1[status] )&&'Table'[call_num]=MAX('Table'[call_num]) )
    )
VAR TIME2 =
    CALCULATE (
        MAX ( 'Table'[begin_date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[status] = SELECTEDVALUE ( 'Slicer 2'[status] )&&'Table'[call_num]=MAX('Table'[call_num])
        )
    )
RETURN
    IF (
        TIME2 > TIME1,
        DATEDIFF ( TIME1, TIME2, MINUTE ),
        DATEDIFF ( TIME2, TIME1, MINUTE )
    )

Step 3, adjust relationship:

vluwangmsft_0-1625105040436.png

And final will get want you want!

vluwangmsft_1-1625105061512.png

 

 

Wish it is helpful for you!

 

Best Regards

Lucien

Many thanks for you help!! you rock!

v-luwang-msft
Community Support
Community Support

Hi @XavierC2 ,

Will different  call_num  with the same status? When this is the case, and a status corresponds to more than one beginning_date, calculate which datediff to choose.Need more details.

 

 

Best Regards

Lucien

Hi @v-luwang-msft ,

here an exemple : 

 

2-161130-000111/30/2016 0:1011/30/2016 0:10911
2-161130-000111/30/2016 0:1011/30/2016 0:10trait
2-161130-000111/30/2016 0:1011/30/2016 0:12cree
2-161130-000111/30/2016 0:1211/30/2016 0:19repa
2-161130-000111/30/2016 0:1911/30/2016 0:24rout
2-161130-000111/30/2016 0:2411/30/2016 0:44lieu
2-161130-000111/30/2016 0:4411/30/2016 1:11tran
2-161130-000111/30/2016 1:1111/30/2016 1:24dest
2-161130-000111/30/2016 1:2411/30/2016 1:40libe
2-161130-000111/30/2016 1:4011/30/2016 2:04reto
2-161130-000111/30/2016 2:0411/30/2016 3:10comp
2-161130-000111/30/2016 3:10 clas
2-161130-000211/30/2016 0:1811/30/2016 0:19911
2-161130-000211/30/2016 0:1911/30/2016 0:19trait
2-161130-000211/30/2016 0:1911/30/2016 0:21cree
2-161130-000211/30/2016 0:2111/30/2016 0:24repa
2-161130-000211/30/2016 0:2411/30/2016 0:30rout
2-161130-000211/30/2016 0:3011/30/2016 0:31lieu
2-161130-000211/30/2016 0:3111/30/2016 1:09aupa
2-161130-000211/30/2016 1:0911/30/2016 1:09tran
2-161130-000211/30/2016 1:0911/30/2016 1:39dest
2-161130-000211/30/2016 1:3911/30/2016 1:44libe
2-161130-000211/30/2016 1:4411/30/2016 1:45reto
2-161130-000211/30/2016 1:4511/30/2016 1:45arrzon
2-161130-000211/30/2016 1:4511/30/2016 1:45comp
2-161130-000211/30/2016 1:45 clas

 

Let's say I am filtering on 911 and cree status, the result should be like this :

 

call_numbegin_date(911)begin_date(cree)date_diff(second)
2-161130-000111/30/2016 0:1011/30/2016 0:1014.0000001
2-161130-000211/30/2016 0:1811/30/2016 0:1924

 

thank you,

 

regards,

 

Xavier

v-luwang-msft
Community Support
Community Support

Hi @XavierC2 ,

Try the following steps:

step1,create two slicer base on status,and create slicer:

vluwangmsft_0-1624959367456.png

then create measure on slicer 2:

Measure = IF(MAX('Slicer 2'[status])=SELECTEDVALUE(Slicer1[status]),BLANK(),1)

vluwangmsft_1-1624959431524.png

Step 2,create measure on base data table:

SILCERchoosedatediff = 
VAR TIME1 =
    CALCULATE (
        MAX ( 'Table'[begin_date] ),
        FILTER ( ALL ( 'Table' ), 'Table'[status] = SELECTEDVALUE ( Slicer1[status] ) )
    )
VAR TIME2 =
    CALCULATE (
        MAX ( 'Table'[begin_date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[status] = SELECTEDVALUE ( 'Slicer 2'[status] )
        )
    )
RETURN
    IF (
        TIME2 > TIME1,
        DATEDIFF ( TIME1, TIME2, MINUTE ),
        DATEDIFF ( TIME2, TIME1, MINUTE )
    )

 

Final you will get you want !

vluwangmsft_2-1624959531908.png

It would probably be much easier to just use a slicer, the following is just a reference:

onlyoneslicer = CALCULATE(DATEDIFF(min('Table'[begin_date]),MAX('Table'[begin_date]),MINUTE),ALLSELECTED('Table'))

vluwangmsft_3-1624959777620.png

 

 

Wish it is helpful for you!

 

Best Regards

Lucien

Thank you very much @v-luwang-msft, it is very helpful. But it only works if there is one call_num, is there a way to make the exact same thing for each call_num in the table? I am trying to do it unsuccessfully for the moment.

 

Thanks,

 

Regards,

 

Xavier

 

v-luwang-msft
Community Support
Community Support

Hi @XavierC2 ,

Not very clearly.

Could you pls provide a sample?

Just for the table ,Slicer A choose value(begin_date):

2021-06-25 13:05:22

 And Slicer B choose value(begin_date):

2021-06-25 14:25:02

And you want to get the time between the two time?

 

 

Best Regards

Lucien

Hi @v-luwang-msft,

 

here some real data

call_numbegin_dateend_datestatus
2-161130-000111/30/2016 0:1011/30/2016 0:10911
2-161130-000111/30/2016 0:1011/30/2016 0:10trait
2-161130-000111/30/2016 0:1011/30/2016 0:12cree
2-161130-000111/30/2016 0:1211/30/2016 0:19repa
2-161130-000111/30/2016 0:1911/30/2016 0:24rout
2-161130-000111/30/2016 0:2411/30/2016 0:44lieu
2-161130-000111/30/2016 0:4411/30/2016 1:11tran
2-161130-000111/30/2016 1:1111/30/2016 1:24dest
2-161130-000111/30/2016 1:2411/30/2016 1:40libe
2-161130-000111/30/2016 1:4011/30/2016 2:04reto
2-161130-000111/30/2016 2:0411/30/2016 3:10comp
2-161130-000111/30/2016 3:10 clas

 

I need people to be able to have intervals between any status :

 

For example, I need people select in a first dropdown the status "tran" and in a second dropdown choose the status "comp"(in the 2nd dropdown, the status "tran" should not be displayed. Once the 2 status are selected, interval between the 2 begin_date should be automatically calculated for every single call_num.

 

Is that clear enough?

 

thank you,

 

regards,

 

Xavier

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.