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
vbourbeau
Resolver II
Resolver II

Use selectedvalue in a column

Hi,

I want to use a slicer for a sample table who are not linked to any other one. 

EX: table 1

Column1

Choice 1

Choice 2

Choice 3

 

In an other table I want to create a column who change dependent the value of the slicer.

I used selectedvalue like this:

column = if(selectedvalue(Table1[Column1]) = "Choice 1", true, false)

 

If I select in the slicer "Choice 1" The result are "False". 

 

If I create a measure with the same syntax it's work? But I need to populate a column not a measure.

 

How can I do that?

 

11 REPLIES 11
MFelix
Super User
Super User

Hi @vbourbeau ,

 

You cannot make a calculated column value change according to the selection on a slicer, believe that you want to make this new column to present on a visual, so you need to make it with a measure.

 

Measures are calculated based on context that can be given by a number of elements including the Slicer.

 

Can you give a little more insight on how you want to use the result of the calculation so I can help you better.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Ok look this example, it's what I'm tying to do. But in my real data I have more table to filter. So if I click on "last week" both table will filter for the last week result. I don't want to create new amount measure on each table because in reality I have 10 tables. 

What I've trying it's create a column in the Date dimension who change value depending the slicer choice and add a page filter for that column.

I put my example here https://we.tl/t-Q6hNDlJyXq

 

2019-08-08 08_49_46-Untitled - Power BI Desktop.png

Hi @vbourbeau ,

 

Looking at your model since you have the tables connect trough date table create the following measure:

 

Filter Dates =
SWITCH (
    TRUE ();
    SELECTEDVALUE ( 'Time'[Sequence] ) = 1; FILTER (
        SUMMARIZE ( Dates; Dates[Date] );
        Dates[Date] <= TODAY ()
            && Dates[Date]
                >= TODAY () - 7
    );
    SELECTEDVALUE ( 'Time'[Sequence] ) = 2; FILTER (
        SUMMARIZE ( Dates; Dates[Date] );
        Dates[Date] <= TODAY ()
            && Dates[Date]
                >= TODAY () - 84
    );
    SELECTEDVALUE ( 'Time'[Sequence] ) = 3; FILTER (
        SUMMARIZE ( Dates; Dates[Date] );
        Dates[Date] <= TODAY ()
            && Dates[Date]
                >= TODAY () - 365
    )
)

Then add this as a filter on your tables and select the option not blank final result will be the following:

 

filter.gif

 

Check the PBIX file attach.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi,

 

When I put the same logic in my full report I've got this message:

 

"A table of multiple values was supplied where a single value was expected"

Can you share the measure you há é created?

Regards,
MFelix

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português




Filter Dates = 
SWITCH (
    TRUE ();
    SELECTEDVALUE ( Temps[Sequence] ) = 1; FILTER (
        SUMMARIZE ( DatesFull;DatesFull[Dates] );
        DatesFull[Dates] <= TODAY ()
            && DatesFull[Dates]
                >= TODAY () - 7
    );
    SELECTEDVALUE ( Temps[Sequence] ) = 2; FILTER (
        SUMMARIZE ( DatesFull;DatesFull[Dates] );
        DatesFull[Dates] <= TODAY ()
            && DatesFull[Dates]
                >= TODAY () - 84
    );
    SELECTEDVALUE ( Temps[Sequence] ) = 3; FILTER (
        SUMMARIZE ( DatesFull;DatesFull[Dates] );
        DatesFull[Dates] <= TODAY ()
            && DatesFull[Dates]
                >= TODAY () - 365
    )
)

If I create a table with :

 FILTER (
        SUMMARIZE ( DatesFull;DatesFull[Dates] );
        DatesFull[Dates] <= TODAY ()
            && DatesFull[Dates]
                >= TODAY () - 7    )

I've got:

2019-08-08 14_07_46-DEV Indicateurs 2.7 - Power BI Desktop.png

 

You see it's missing 2 days because of the week end. Maybe it's the cause... 

I changed my Date dimension to be sure to have continus date but still have the same problem.

2019-08-08 15_24_05-DEV temps Indicateurs 2.7 - Copie - Power BI Desktop.png

 

2019-08-08 15_28_12-DEV temps Indicateurs 2.7 - Copie - Power BI Desktop.png

Hi @vbourbeau ,

 

Are you creating a calculate column or measure? you must use a measure not a column.

 

Is it possible for you to share your file trough private message? sometimes the context changes the way calculations are made.

 

Regarding the weekend you just need to adjust the calculation I have made one week from today but if you want the full week of the current date, some adjustments need to be made.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @vbourbeau ,

 

You issue is relatwed to the fact that if you have 5 types and if you select one that is not on the switch measure it will give you error, you need to add the other option to the switch formula or add an IFERROR so that it does not return error.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



I put the exact same number on the switch the problem still there.

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.