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
Mann
Resolver III
Resolver III

Grouping with Measure in Table Visual and Filtering from Unrelated Slicer

Hi Guys,

 

I have table in source like this:

IDNameSupplierShiftDateEntry TimeExit Time
1JohnADS20-Mar-203/20/2020 4AM3/20/2020 2PM
1JohnADS20-Mar-203/20/2020 3PM3/20/2020 10PM
1JohnBDS21-Mar-203/21/2020 11AM3/20/2020 11PM
2MaxADS18-Mar-203/18/2020 4AM3/18/2020 9AM
2MaxADS18-Mar-203/18/2020 1PM3/18/2020 8PM
2MaxANS18-Mar-203/18/2020 9PM3/18/2020 11PM
2MaxBDS20-Mar-203/20/2020 4AM3/20/2020 2PM
2MaxBDS20-Mar-203/20/2020 3PM3/20/2020 10PM
3PhilipCNS21-Mar-203/21/2020 1PM3/21/2020 10PM
3PhilipADS22-Mar-203/22/2020 3PM3/22/2020 8PM

 

I want to create a table visual from this considering slicers like below:

IDNameSupplierDateFirst Entry TimeLast Exit Time
1JohnA20-Mar-203/20/2020 4AM3/20/2020 10PM
1JohnB21-Mar-203/21/2020 11AM3/20/2020 11PM
2MaxA18-Mar-203/18/2020 4AM3/18/2020 8PM
2MaxB20-Mar-203/20/2020 4AM3/20/2020 2PM

 

There are two slicers on report:

(1) Date slicer coming from unrelated table 

(2) Shift Slicer coming from unrelated table

Note: Above example of table visual is when "DS" is selected from Shift Type slicer and Date= 18 March, 20 March, 21 March is selected from Date slicer. Table visual will not have any column of Shift.

 

I have few challenges to get the following done like:

1. I want to show first entry time and last entry time as per shift selection like if "DS" is selected then first entry time and last exit time needs to be calculated accordingly. Same way when NS is selected or both DS & NS is selected. Shift Slicer is coming from different table can't create relationships.

2. There is date slicer which is coming from a separate table and this table is not connected to the source table. (I can't create relationship due to some constraint). When any one or multiple dates are selected from this slicer final table visual should get filter for e.g. if date slicer selection is of "18 March" and "20 March" then records of 18 and 20 March should be shown.

 

Can we achieve the above without creating any intermediate calculated table or relationships. I can only work with measures.

 

Thanks

Mann

1 ACCEPTED SOLUTION

Hi Liang,

 

Thanks for checking on this. I checked the report attached. 

First thing: Date slicer and Shift slicer are coming from two different unrelated tables.

 

Also, I managed to find the solution without showing shift type in table:

I created "Test Date" measure which I added in visual level filter and filter it to always 1 as shown:

 

Test Date = 
If(SELECTEDVALUE('table'[Date]) IN VALUES('Table 2'[date]),1,0)

 

 Then I created the below two measures for First Entry Time and Last Exit Time:

 

 

First Entry Time = 
VAR DS=
CALCULATE (
    FIRSTNONBLANK ( 'table'[Entry Time], 1 ),
    'table'[Shift] = "DS"
)
VAR NS=
CALCULATE (
    FIRSTNONBLANK ( 'table'[Entry Time], 1 ),
    'table'[Shift] = "NS"
)
VAR DSNS=
CALCULATE(
    FIRSTNONBLANK ( 'table'[Entry Time], 1 ))
Return
SWITCH(TRUE(),
SELECTEDVALUE('Table 3'[shift])= "DS",DS,
SELECTEDVALUE('Table 3'[shift])= "NS",NS,DSNS)

 

 

Last Exit Time = 
VAR DS=
CALCULATE (
    LASTNONBLANK ( 'table'[Exit Time], 1 ),
    'table'[Shift] = "DS"
)
VAR NS=
CALCULATE (
    LASTNONBLANK ( 'table'[Exit Time], 1 ),
    'table'[Shift] = "NS"
)
VAR DSNS=
CALCULATE(
    LASTNONBLANK ( 'table'[Exit Time], 1 ))
Return
SWITCH(TRUE(),
SELECTEDVALUE('Table 3'[shift])= "DS",DS,
SELECTEDVALUE('Table 3'[shift])= "NS",NS,DSNS)

Thanks for your help on this.

 

Mann.

View solution in original post

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @Mann ,

 

I created three measures.

 

First Entry Time = CALCULATE(MIN('table'[Entry Time]),ALLEXCEPT('table','table'[Date],'table'[ID],'table'[Supplier],'table'[Shift]))

Last Exit Time = CALCULATE(MAX('table'[Exit Time]),ALLEXCEPT('table','table'[ID],'table'[Date],'table'[Supplier],'table'[Shift]))

condiition = IF(MAX('table'[Date])in VALUES('Table 2'[date])&&(MAX('table'[Shift])in VALUES('Table 2'[shift])),1)

 

 

When I add [shift] column to the chart and apply [condition] to the visual level filter, I can get the result you want.

test_grouping.PNG

Sample .pbix

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Liang,

 

Thanks for checking on this. I checked the report attached. 

First thing: Date slicer and Shift slicer are coming from two different unrelated tables.

 

Also, I managed to find the solution without showing shift type in table:

I created "Test Date" measure which I added in visual level filter and filter it to always 1 as shown:

 

Test Date = 
If(SELECTEDVALUE('table'[Date]) IN VALUES('Table 2'[date]),1,0)

 

 Then I created the below two measures for First Entry Time and Last Exit Time:

 

 

First Entry Time = 
VAR DS=
CALCULATE (
    FIRSTNONBLANK ( 'table'[Entry Time], 1 ),
    'table'[Shift] = "DS"
)
VAR NS=
CALCULATE (
    FIRSTNONBLANK ( 'table'[Entry Time], 1 ),
    'table'[Shift] = "NS"
)
VAR DSNS=
CALCULATE(
    FIRSTNONBLANK ( 'table'[Entry Time], 1 ))
Return
SWITCH(TRUE(),
SELECTEDVALUE('Table 3'[shift])= "DS",DS,
SELECTEDVALUE('Table 3'[shift])= "NS",NS,DSNS)

 

 

Last Exit Time = 
VAR DS=
CALCULATE (
    LASTNONBLANK ( 'table'[Exit Time], 1 ),
    'table'[Shift] = "DS"
)
VAR NS=
CALCULATE (
    LASTNONBLANK ( 'table'[Exit Time], 1 ),
    'table'[Shift] = "NS"
)
VAR DSNS=
CALCULATE(
    LASTNONBLANK ( 'table'[Exit Time], 1 ))
Return
SWITCH(TRUE(),
SELECTEDVALUE('Table 3'[shift])= "DS",DS,
SELECTEDVALUE('Table 3'[shift])= "NS",NS,DSNS)

Thanks for your help on this.

 

Mann.

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.