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
MurtoMan
Helper I
Helper I

Slicer for certain values

I have a visualization that shows a comparison of certain values. 

There is a simple calculation like Value A * Value B = Result (in bars)

MurtoMan_0-1713952319463.png

I want a slicer like this that changes only few certain values in Value A and it should show percentage between 0 - 100 (not values itself)

MurtoMan_1-1713952644265.png

What kind of DAX code should I use?

 

 

 

1 ACCEPTED SOLUTION

Hi @MurtoMan ,

The Table data is shown below:

vzhouwenmsft_0-1714119478391.png

Please follow these steps:
1. Use the following DAX expression to create a Table

 

Table 2 = GENERATESERIES(1,100,1)

 

vzhouwenmsft_1-1714119520177.png

2.Use the following DAX expression to create a measure

 

Result = 
VAR _a = SELECTEDVALUE('Table'[Item])
VAR _b = SELECTEDVALUE('Table'[Factor])
VAR _c = SELECTEDVALUE('Table'[Value])
RETURN
IF( _a = "Shoes",
DIVIDE(_b,100) * MAX('Table 2'[Value]) * _c   , _b * _c
)

 

3.Use the following DAX expression to create a measure

 

_Factor = IF( SELECTEDVALUE('Table'[Item]) = "Shoes", DIVIDE(SELECTEDVALUE('Table'[Factor]),100) * MAX('Table 2'[Value]),SELECTEDVALUE('Table'[Factor]))

 

4.Final output

vzhouwenmsft_8-1714119888198.png

vzhouwenmsft_9-1714119897213.png

 

 

vzhouwenmsft_4-1714119602587.png

vzhouwenmsft_5-1714119614443.png

 

vzhouwenmsft_10-1714119926427.png

vzhouwenmsft_11-1714119942231.png

 

Best Regards,
Wenbin Zhou
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

10 REPLIES 10
Syndicate_Admin
Administrator
Administrator

Hi Wenbin,

This looks reasonable, but can you explain what is the purpose of this table?

Are these 3 values enough?

MurtoMan_0-1714023159562.png

Hi @MurtoMan , @Syndicate_Admin ,

Regarding your question, this expression creates a table of consecutive values.(Starting at 0 and ending at 1.01, each increase is 0.01, i.e., 1 percent.)

GENERATESERIES function - DAX | Microsoft Learn

This allows you to select the corresponding value via the slicer.

vzhouwenmsft_0-1714023886692.png

 

Hi, @v-zhouwen-msft 

Ok I see.

 

But what comes to Index there is a problem.

Values A or B are not unique. So there would be different index values for same values A or B.

MurtoMan_0-1714026890879.png

 

 

Hi @MurtoMan ,

What are your expected outcomes? Is it to change all the 0.35 in column 'Value A' to the selection in the slicer?

The expression I provided should be able to find the value in the corresponding column 'Value B' based on the index column

vzhouwenmsft_0-1714028098456.png

I modified the table data.

vzhouwenmsft_1-1714028431257.png

1.With no slicer selected(0.35 = 0.35 *1    0.7 = 0.35 *2   0.7 = 0.35 * 2 ........)

vzhouwenmsft_2-1714028497292.png

2.After selecting the slicer(0.96 = 0.96 * 1    1.92 = 0.96 *2   1.92 = 0.96 * 2 ......)

vzhouwenmsft_3-1714028576708.png

 

Hi,

 

Yes the expected outcome is to change values in column 'Value A' with a slicer.

But indexing doesn't work in my case because max index is restricted to 1000. However, I have several million rows in my data.

Hi @v-zhouwen-msft 

 

Let's put it in this way.

 

I have a table like this and I want to change the factor with a slicer in Power BI Desktop.

 

MurtoMan_0-1714111060094.png

 

It's easy to create a slicer like this for factor values

MurtoMan_1-1714111120620.png

But I want to turn the values in the slicer for shoes only from real values to percents (between 0 - 100).

What is the way to do that?

Big thanks @v-zhouwen-msft !

Now it works like a charm 😊

One extra question.

Is there a way to show total SUM of this Result column?

MurtoMan_1-1714125856841.png

 

 

Hi @MurtoMan ,

The Table data is shown below:

vzhouwenmsft_0-1714119478391.png

Please follow these steps:
1. Use the following DAX expression to create a Table

 

Table 2 = GENERATESERIES(1,100,1)

 

vzhouwenmsft_1-1714119520177.png

2.Use the following DAX expression to create a measure

 

Result = 
VAR _a = SELECTEDVALUE('Table'[Item])
VAR _b = SELECTEDVALUE('Table'[Factor])
VAR _c = SELECTEDVALUE('Table'[Value])
RETURN
IF( _a = "Shoes",
DIVIDE(_b,100) * MAX('Table 2'[Value]) * _c   , _b * _c
)

 

3.Use the following DAX expression to create a measure

 

_Factor = IF( SELECTEDVALUE('Table'[Item]) = "Shoes", DIVIDE(SELECTEDVALUE('Table'[Factor]),100) * MAX('Table 2'[Value]),SELECTEDVALUE('Table'[Factor]))

 

4.Final output

vzhouwenmsft_8-1714119888198.png

vzhouwenmsft_9-1714119897213.png

 

 

vzhouwenmsft_4-1714119602587.png

vzhouwenmsft_5-1714119614443.png

 

vzhouwenmsft_10-1714119926427.png

vzhouwenmsft_11-1714119942231.png

 

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

v-zhouwen-msft
Community Support
Community Support

Hi @MurtoMan ,

Regarding your question, this is my thought process.

The Table data is shown below:

vzhouwenmsft_0-1714012931271.png

Please follow these steps:

1.Add an index column to determine which values to modify with the slicer.

vzhouwenmsft_1-1714013017211.png

2.Use the following DAX expression to create a table

 

Table 2 = GENERATESERIES(0.00,1.01,0.01)

 

3.Use the following DAX expression to create a measure(Assuming that the index columns corresponding to the specific values to be modified are 1, 2, 3)

 

MEASURE =
VAR _a =
    MAX ( 'Table 2'[Value] )
VAR _b =
    IF (
        _a = CALCULATE ( MAX ( 'Table 2'[Value] ), ALL ( 'Table 2' ) ),
        SUM ( 'Table'[Value A] ) * SUM ( 'Table'[Value B] ),
        IF (
            SELECTEDVALUE ( 'Table'[Index] ) IN { 1, 2, 3 },
            _a
                * SUMX (
                    FILTER ( 'Table', 'Table'[Index] = SELECTEDVALUE ( 'Table'[Index] ) ),
                    'Table'[Value B]
                ),
            SUM ( 'Table'[Value A] ) * SUM ( 'Table'[Value B] )
        )
    )
RETURN
    _b

 

3.Final output

Displays the default value when the slicer has not made a selection.

vzhouwenmsft_2-1714013196256.png

vzhouwenmsft_3-1714013212584.png

vzhouwenmsft_4-1714013239406.png

vzhouwenmsft_5-1714013269090.png

vzhouwenmsft_7-1714013591913.png

 

After selecting the slicer

vzhouwenmsft_6-1714013420199.png

 


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

 

 

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.