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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
oqueffelec
New Member

SelectedValue from slicer to measure

Hi, 

 

I have a table Veh_classif_Standardized, in which each row is a unique customer identified by the field VIN.

Each customer has a group field (group 1, 2 or 3) and a total amount spent field.

On my report, I want to create a VIN slicer so that when i click on a VIN, I get the customer's total amount spent on a card and the total amount spent average of his group on a second card.

 

 

To do so, I created 2 DAX measures : 

CurrentGroup = SELECTEDVALUE(Veh_classif_Standardized[Groupe n°])

SpentAverageCurrentGroup = CALCULATE(AVERAGE(Veh_classif_Standardized[TotalSpent]);FILTER(Veh_classif_Standardized;Veh_classif_Standardized[Groupe n°] = [CurrentGroup]))

 

However this does not seem to work : when I change in the slicer from a customer in a group to another customer in another group, the card with SpentAverageCurrentGroup always gives me the average of the entire table and not the average of the current group.

 

I would like to know what the corrrect way to do this is.  

  

Any help much appreciated ! 

2 REPLIES 2
Anonymous
Not applicable

Hi,

 

would be better if we could get a sample of data to work with, but off the top of my head, could you try moving your var declaration inside your calculate statement, maybe this would work?

 

CALCULATE (
    VAR CurrentGroup =
        SELECTEDVALUE ( Veh_classif_Standardized[Groupe n°] )
    RETURN
        AVERAGE ( Veh_classif_Standardized[TotalSpent] );
    Veh_classif_Standardized[Groupe n°] = CurrentGroup
)
dedelman_clng
Community Champion
Community Champion

with CALCULATE, you don't always have to explicitly use the FILTER function

 

try

 

SpentAverageCurrentGroup = 
CALCULATE
(
 AVERAGE(Veh_classif_Standardized[TotalSpent]),
 Veh_classif_Standardized[Groupe n°] = [CurrentGroup]
)

You could also try to put code for CurrentGroup into a variable call within a single expression

 

SpentAverageCurrentGroup = 
var CG = SELECTEDVALUE(Veh_classif_Standardized[Groupe n°])
return
CALCULATE
(
 AVERAGE(Veh_classif_Standardized[TotalSpent]),
 Veh_classif_Standardized[Groupe n°] = [CurrentGroup]
)

 

Hope this helps

David

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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