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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mel0001
New Member

IF Function dependent on Slicer with result coming from different columns

Hi, I have two Data sets as below.

Table 1:

ProductYTD1YTD2YTD3Total
A10151237
B5218
C61310
Total   55

 

Table 2:

MonthYTD
JanYTD1
FebYTD2
MarYTD3

 

I want to create a NewColumn (or maybe a new measure) in Table 1 which is dependent on a Slicer (value: Jan, Feb, Mar) in the Report. 

For example, if filtered value is "Jan" in the slicer, the NewColumn will get YTD1 column, if "Feb", then it will get YTD2 column. 

 

What is the way to do this? 

 

Thank you! 

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi  , 

1. Create a table via 

Table = union(VALUES(Table2[YTD]),{"NewColumn"})
 
2. Put the new column [YTD] in 'Table' into Columns of matrix table.

vchenwuzmsft_2-1649755180404.png

 


3. Create a mesure use the following code:

Measure =
VAR _sum =
    CALCULATE (
        SUM ( Table1[Value] ),
        'Table1'[YTD] = SELECTEDVALUE ( 'Table'[YTD] )
    )
VAR _newcolumn =
    CALCULATE (
        SUM ( Table1[Value] ),
        'Table1'[YTD] = SELECTEDVALUE ( Table2[YTD] )
    )
RETURN
    IF (
        HASONEVALUE ( 'Table'[YTD] ),
        IF ( SELECTEDVALUE ( 'Table'[YTD] ) = "newcolumn", _newcolumn, _sum ),
        SUM ( Table1[Value] ) + _newcolumn
    )

 

Result:

vchenwuzmsft_3-1649755217776.png

 

Pbix in the end you can refer.
Best Regards

Community Support Team _ chenwu zhu

 

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

3 REPLIES 3
PC2790
Community Champion
Community Champion
v-chenwuz-msft
Community Support
Community Support

Hi  , 

1. Create a table via 

Table = union(VALUES(Table2[YTD]),{"NewColumn"})
 
2. Put the new column [YTD] in 'Table' into Columns of matrix table.

vchenwuzmsft_2-1649755180404.png

 


3. Create a mesure use the following code:

Measure =
VAR _sum =
    CALCULATE (
        SUM ( Table1[Value] ),
        'Table1'[YTD] = SELECTEDVALUE ( 'Table'[YTD] )
    )
VAR _newcolumn =
    CALCULATE (
        SUM ( Table1[Value] ),
        'Table1'[YTD] = SELECTEDVALUE ( Table2[YTD] )
    )
RETURN
    IF (
        HASONEVALUE ( 'Table'[YTD] ),
        IF ( SELECTEDVALUE ( 'Table'[YTD] ) = "newcolumn", _newcolumn, _sum ),
        SUM ( Table1[Value] ) + _newcolumn
    )

 

Result:

vchenwuzmsft_3-1649755217776.png

 

Pbix in the end you can refer.
Best Regards

Community Support Team _ chenwu zhu

 

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

lbendlin
Super User
Super User

A slicer choice cannot create a column. It can impact a measure. Read about SELECTEDVALUE() and SWITCH() 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.