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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
sshokri89
Helper I
Helper I

Measure to return a value (from a column) based on another measure

Hi everyone,

 

I need help with this measure; I have a column in  Query1[StartDate] table. Based on that, I have created 3 scenarios and created 3 EndDate columns.

 

It's actually not important to explain my scenarios but they "standard contract" , "Only 3Y contract" , and "Max 3Y contract".  To sum up, I have created one EndDate based on each scenario: "EndDate_standardcontract" , "EndDate_Only3Ycontract" , and "EndDate_Max3Ycontract". 

 

Now I got stuck a step further, where I have brought my 3 scenarios as filters on the page, and I need to show create ONLY ONE column for my EndDate. And that column obviously needs to work in sync with the filter selection. e.g. If the user selects "Only 3Y contract", then my EndDate column needs to show the value from that column, and likewise for the other 3 scenarios.


I tried a few times but the core part of it was the switch function below (that I couldnt make it work):

 

End Date Dynamic = SWITCH(
       TRUE(),
       SELECTEDVALUE(Scenario[Options])="Standard contract",Values(Query1[EndDate_standardcontract]),
       SELECTEDVALUE(Scenario[Options])="Only 3Y contract",VALUES(Query1[EndDate_Only3Ycontract]),
       SELECTEDVALUE(Scenario[Options])="Max 3Y contract",VALUES(Query1[EndDate_Max3Ycontract]),
       0
)

 

 Thanks in advance for your help.

1 ACCEPTED SOLUTION
ebeery
Solution Sage
Solution Sage

@sshokri89 the VALUES function returns a table not a scalar value, so you won't be able to use it in a measure in the way you're showing above.  I'm guessing you got an error like below:

ebeery_0-1639714589333.png

 

Depending on the context in which you are using this measure (if it's a table/matrix?), consider using SELECTEDVALUE instead of VALUES.

Below is a very simple example with some dummy data where I'm switching between a few different dates (similar to your "scenarios").

ebeery_1-1639714879887.pngebeery_4-1639715053155.png

 

 

SelectedDate = 
VAR _SelectedDate = SELECTEDVALUE('Table'[SelectedDate])
Return
SWITCH(
    TRUE(),
    _SelectedDate = "DueDate", SELECTEDVALUE(Sales[DueDate]),
    _SelectedDate = "OrderDate",SELECTEDVALUE(Sales[OrderDate]),
    _SelectedDate = "ShipDate", SELECTEDVALUE(Sales[ShipDate])
)

 

  

View solution in original post

2 REPLIES 2
sshokri89
Helper I
Helper I

Thanks a lot. I see what I was missing now 🙂

ebeery
Solution Sage
Solution Sage

@sshokri89 the VALUES function returns a table not a scalar value, so you won't be able to use it in a measure in the way you're showing above.  I'm guessing you got an error like below:

ebeery_0-1639714589333.png

 

Depending on the context in which you are using this measure (if it's a table/matrix?), consider using SELECTEDVALUE instead of VALUES.

Below is a very simple example with some dummy data where I'm switching between a few different dates (similar to your "scenarios").

ebeery_1-1639714879887.pngebeery_4-1639715053155.png

 

 

SelectedDate = 
VAR _SelectedDate = SELECTEDVALUE('Table'[SelectedDate])
Return
SWITCH(
    TRUE(),
    _SelectedDate = "DueDate", SELECTEDVALUE(Sales[DueDate]),
    _SelectedDate = "OrderDate",SELECTEDVALUE(Sales[OrderDate]),
    _SelectedDate = "ShipDate", SELECTEDVALUE(Sales[ShipDate])
)

 

  

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.