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 dynamically change dimension field in table visual with a sort

I want to dynamically change a dimension field in a table visual according to a slicer selection.  I know that this has 2 usual solutions, as described here:

https://www.thedataschool.com.au/danica-hui/switching-dimensions-in-power-bi/

 

However, in my case, I also want:

1) the dimension field values to be custom sorted

2) the slicer selection to drive the filtering of another dimension table

 

 

I have the following data:

 

Fact Posted Labor

Employee KeyWeek KeyTime (Hours)
11

5

2110
125
225
1315
235
1410
2420

 

Dimension Week

Week KeyUS HolidayJamaica Holiday
1

no holiday

no holiday
2Presidents Dayno holiday
3no holidayEaster
4ThanksgivingThanksgiving

 

Dimension Employee

Employee KeyEmployee NameHoliday Type
1John DoeUS Holiday
2Jane DoeJamaica Holiday

 

Holiday Sort

Holiday TypeHolidayHoliday Sort Order
US HolidayPresidents Day1
US Holidayno holiday2
US HolidayThanksgiving3
Jamaica HolidayEaster1
Jamaica HolidayThanksgiving2
Jamaica Holidayno holiday3

 

My measure is:

Total Time = sum of posted labor time = SUM('Fact Posted Labor'[Time (Hours)])

 

I want a table visual of Holiday and Total Time, where the Holiday values will be dynamic relative to a slicer selection and where the holidays are sorted per the 'Holiday Sort' table above.  The values in the slicer will be the distinct [Holiday Type] values in 'Dimension Employee' (which is identical to the two "holiday" columns in 'Dimension Week').  Again, not only does the selection of values need to determine what holidays appear in the table visual, but it must also filter the 'Fact Posted Labor' table as appropriate relative to the 'Dimension Employee' table.

 

So, with a selection of "US Holiday" in the slicer, my expected output is:

HolidayTotal Time
Presidents Day5
no holiday20
Thanksgiving10

 

obtained from:

[Employee Key] = 1 (i.e., the only US employee, as per 'Dimension Employee'):

    [Holiday] is all distinct 'Dimension Week'[US Holiday] values:

        "no holiday" (i.e., weeks 1 and 3) = 5 + 15 = 20      (sort order 2)

        "Presidents Day"(i.e., week 2) = 5                           (sort order 1)

        "hanksgiving"(i.e., week 4) = 10                             (sort order 3)

 

And, with a selection of "Jamaica Holiday" my expected output is:

HolidayTotal Time
Easter5
Thanksgiving20
no holiday15

 

obtained from:

[Employee Key] = 2 (i.e., the only Jamaica employee, as per 'Dimension Employee'):

    [Holiday] is all distinct 'Dimension Week'[Jamaica Holiday] values:

        "Easter" (i.e., week 3) = 5                                        (sort order 1)

        "no holiday" (i.e., weeks 1 and 2) = 10 + 5 = 15     (sort order 3)

        "Thanksgiving" (i.e., week 4) = 20                           (sort order 2)

 

How can I achieve this?  A bookmark solution is not permissible.

3 REPLIES 3
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

I don't think it's possible to order a column when the column values are duplicated, I think PBI doesn't allow it because of context filter.

However, I tried another solution that can work for you.

 

You can add the sort order column to your table, sort the table by this column and hide the column (just drag the column till you hide it).

 

It's gonna work only for table/matrix.

 

I will continue thinking about a better solution for it.

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

@camargos88 

Thank you for looking into it.

 

By the way, I have created a solution for toggling the dimension field in my table.  The solution I am using is to create 2 new tables branched off of the Dimension Week table.  The first one is a "slicer" table.  Its structure is:

Holiday Slicer

Holiday
US Holiday
Jamaica Holiday

 

The second one is a "joiner" table.  Its structure is:

bridge

Week KeyHoliday
1US Holiday
1Jamaica Holiday
2US Holiday
2Jamaica Holiday
3US Holiday
3Jamaica Holiday
4US Holiday
4Jamaica Holiday

 

I then put a DAX column onto the bridge table as:

FetchHoliday =
SWITCH(
    FIRSTNONBLANK(
        'Holiday Slicer'[Holiday]
        ,1
    )
    ,"US Holiday", RELATED('Dimension Week'[US Holiday])
    ,"Jamaica Holiday", RELATED('Dimension Week'[Jamaica Holiday])
)
 
I then wire up the tables with many-to-many relationships as follows:
PBI 20200323.png
 
Lastly, I create a slicer from 'Holiday Slicer'[Holiday] and a table visual from 'bridge'[FetchHoliday] with measure [Total Time], as follows:
 
PBI 20200323 - 2.pngPBI 20200323 - 3.png
Anonymous
Not applicable

My solution does not solve the problem of filtering the Dimension Employee table to the correct rows.  A work-around I have is to have the user make the same selection in 2 slicers -- one that drives which holidays appear in the table visual, and another one that drives the Dimension Employee filtering.  Obviously, this isn't ideal.  So, I need a solution that resolves this problem as well as the sorting problem.

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.