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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors