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

Get previous value according to the Slicer

Hi,

 

I hope you can help.

 

I have a sliver with 3 options, OP1, OP2, OP3.

No I have a line graph with these Options in the x-Axis and some values.

Now I want to show in the tooltip eg at OP1previous, which would be OP2, in OP2 the previous is value of OP3. This works fine so far.

But now, when i select in the slicer OP1 and OP3, I want to see in OP1 not as previous OP2, but OP3.

 

Does someone know how to implement this?

 

Thanks!

1 ACCEPTED SOLUTION

Hi @v-yulgu-msft,

 

thanks for your reply. It was almost what was looking for! Your code only works if you have two values selected.

I analysed what you did and changed it that way, that it works for as many selection as I need.

I changed the rank to two groupings

Rank = 
RANKX (
    ALLSELECTED ( 'Get Previous' );
    CALCULATE (
        SUM ( 'Get Previous'[Index] );
        ALLEXCEPT ( 'Get previous'; 'Get Previous'[Opt];'Get Previous'[Account] )
    );
    ;
    ASC
)

and the main changes in the "Previous" measure:

 

Previous = 
VAR currentrank = [Rank]
RETURN
    CALCULATE (
        sum('Get Previous'[Amount]);
		FILTER ( ALLSELECTED ( 'Get previous' ); [Rank] = currentrank + 1 )
    )

 

 

I hope that also helps others.

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @NerdFlanders,

 

Below is the result in my test for your reference.

 

Suppose this is the source table.

1.PNG

 

In this table, please add an index column in Query Edit mode.

2.PNG  3.PNG

 

Create a measure named as [Rank!] which returns order number.

Rank! =
RANKX (
    ALLSELECTED ( 'Get previous' ),
    CALCULATE (
        SUM ( 'Get previous'[Index] ),
        ALLEXCEPT ( 'Get previous', 'Get previous'[Category] )
    ),
    ,
    ASC
)

Create a measure to dynamically get previous value based on slicer selection.

Previous =
VAR currentrank = [Rank!]
RETURN
    CALCULATE (
        FIRSTNONBLANK ( 'Get previous'[Values], 1 ),
        FILTER ( ALLSELECTED ( 'Get previous' ), [Rank!] > currentrank )
    )

Result.

4.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yulgu-msft,

 

thanks for your reply. It was almost what was looking for! Your code only works if you have two values selected.

I analysed what you did and changed it that way, that it works for as many selection as I need.

I changed the rank to two groupings

Rank = 
RANKX (
    ALLSELECTED ( 'Get Previous' );
    CALCULATE (
        SUM ( 'Get Previous'[Index] );
        ALLEXCEPT ( 'Get previous'; 'Get Previous'[Opt];'Get Previous'[Account] )
    );
    ;
    ASC
)

and the main changes in the "Previous" measure:

 

Previous = 
VAR currentrank = [Rank]
RETURN
    CALCULATE (
        sum('Get Previous'[Amount]);
		FILTER ( ALLSELECTED ( 'Get previous' ); [Rank] = currentrank + 1 )
    )

 

 

I hope that also helps others.

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.