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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
orlando9427
Frequent Visitor

Measure with different filters based on row value

Hi,

 

I'm trying to generate a measure with total sales per division. Each division has its own way of calculate sales and they are stored in a table like this.

DIVISIONDIVISION_NAME
0B2B
1B2C

Originally I used a Measured Column with the function SWITCH so each case has its own filters, like this.

 

 

 

Measured Column = SWITCH([DIVISION], 
0, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] = 1),
1, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] <> 1 && SALES[B] <> 1)
)

 

 

So I get something like this

DIVISIONDIVISION_NAMEMeasured Column
0B2B150000
1B2C48000

That worked fine until the necessity of apply time comparison via visual slicer, the problem is that the measure don't apply time filtering so I get always the total sales.

I understand that measured columns are not restricted to visuals, but if I use a Measure it gives me and error when using the SWITCH function, is there a way to do this?

 

Thanks a lot for your help!

 

PS. Sorry for my bad English.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@orlando9427 , Based on whatI got

 

For correct grand total

Measured = Sumx(values([DIVISION]) , SWITCH([DIVISION],
0, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] = 1)),
1, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] <> 1 && SALES[B] <> 1)
)) )

 


for GT in each row

 

Grand total Measured = calculate( Sumx(values([DIVISION]) , SWITCH([DIVISION],
0, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] = 1)),
1, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] <> 1 && SALES[B] <> 1)
))), allselected())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @orlando9427 ,

I created some data:

vyangliumsft_0-1698308206737.png

 

You can use the ALLSELECT() function and the results will change with the filtered range

Here are the steps you can follow:

1. Create measure.

Measure =
SWITCH(
    TRUE(),
    MAX('Table'[DIVISION])= 0,
    SUMX(
        FILTER(ALLSELECTED(Sales),
        'Sales'[A]=1),[TOTAL_PRICE]),
    MAX('Table'[DIVISION])=1,
    SUMX(
        FILTER(ALLSELECTED('Sales'),
        'Sales'[A]<>1&&'Sales'[B]<>1),[TOTAL_PRICE]))

2. Result:

vyangliumsft_1-1698308206738.png

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@orlando9427 , Based on whatI got

 

For correct grand total

Measured = Sumx(values([DIVISION]) , SWITCH([DIVISION],
0, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] = 1)),
1, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] <> 1 && SALES[B] <> 1)
)) )

 


for GT in each row

 

Grand total Measured = calculate( Sumx(values([DIVISION]) , SWITCH([DIVISION],
0, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] = 1)),
1, CALCULATE(SUM(SALES[TOTAL_PRICE]), FILTER(SALES, SALES[A] <> 1 && SALES[B] <> 1)
))), allselected())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks a lot! I worked as intended

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors