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
Matt_Alexander
Advocate III
Advocate III

Previous Value from slicer selection

Hi, 

 

Wondering if anyone can help me on this one:

 

I have the following simple measure: 

Total = COUNTROWS('Fleet (Cars)')

In another table we have the labels for year ranges such as:

 

 

RangeIndex
2017-20181
2018-20192

 

When the user clicks the slicer, it shows the number of rows for that period, but I could also like to automatically show the previous period. I have tried with things like the following but to no avail.

 

Previous = CALCULATE(COUNTROWS('Fleet (Cars)');'Ranges'[Index]-1)

Any suggestions how I could achieve this?

 

Many thanks, 

 

Matt

 

 

1 ACCEPTED SOLUTION

Hi again, 

 

Just to let you know we've managed to figure it out with the following:

 

var a = CALCULATE(Max('Ranges'[Index])-1)
var b = CALCULATE(
DISTINCTCOUNT('Fleet (Cars)'[id]);
filter(
ALL('Fleet (Cars)');true());'Ranges'[Index]=a;) return b

Regards, 

 

Matt

View solution in original post

5 REPLIES 5
Zubair_Muhammad
Community Champion
Community Champion

Hi @Matt_Alexander

 

Give this a shot

 

Previous =
CALCULATE (
    COUNTROWS ( 'Fleet (Cars)' ),
    FILTER (
        ALL ( 'Ranges'[Index] ),
        'Ranges'[Index]
            = SELECTEDVALUE ( 'Ranges'[Index] ) - 1
    )
)

Regards
Zubair

Please try my custom visuals

Thanks @Zubair_Muhammad but getting a multiple column error on this one:

 

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

 

 

Hi @Matt_Alexander

 

Could you show me a screen shot? or share the file?

How are the tables related?


Regards
Zubair

Please try my custom visuals

Relation is a bidireccional one to many between the IDs of the ranges:

 

Ranges.PNG

 

@Zubair_Muhammad Thanks for your assistance!

 

Matt

Hi again, 

 

Just to let you know we've managed to figure it out with the following:

 

var a = CALCULATE(Max('Ranges'[Index])-1)
var b = CALCULATE(
DISTINCTCOUNT('Fleet (Cars)'[id]);
filter(
ALL('Fleet (Cars)');true());'Ranges'[Index]=a;) return b

Regards, 

 

Matt

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.