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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
hsing121
Regular Visitor

DAX - filter the table first on slicer and then exclude slicer while calculating sum

I have below table and a multi select slicer on boot duration . i want a selectedvalue column that gives total of O Success for each vehicle id but it should only total over the selected boot_minutes_duration in the slicer. 

II used the below calculation but that gives overall sum for each vehicle id does not matter what boot duration i select in the slicer

selectedvalue = CALCULATE (
    SUM ( Projection_Boot_Status_By_Vehicle_Id[optimistic_success] ),
        ALLEXCEPT (
            Projection_Boot_Status_By_Vehicle_Id,
            Projection_Boot_Status_By_Vehicle_Id[vehicle_id],
            Projection_Boot_Status_By_Vehicle_Id[branch_version],
            Projection_Boot_Status_By_Vehicle_Id[sub_branch_version]
        )
)

 

vehicle_idO SuccessO FailSB%boot_minutes_durationselectedvalueBD%P SuccessP FailSB%BD%SubBranch
0B954435BB8BB1EDBDCAA067F7E4773380A96EBF0CE7D1B9D6C33214C5B0672712195% >7 Min2192%11291%85%2.3.3
0B954435BB8BB1EDBDCAA067F7E4773380A96EBF0CE7D1B9D6C33214C5B067272095%5-7 Min21100%2091%100%2.3.3
0B954435BB8BB1EDBDCAA067F7E4773380A96EBF0CE7D1B9D6C33214C5B067274095%3-5 Min21100%4091%100%2.3.3
0B954435BB8BB1EDBDCAA067F7E4773380A96EBF0CE7D1B9D6C33214C5B067273095%<= 3 Min21100%3091%100%2.3.3
133C188488679EDA33700DD3BCB78A2591D9B304A8077A0F7AD38C61DC2DA60124194% >7 Min3396%23291%92%2.3.3
133C188488679EDA33700DD3BCB78A2591D9B304A8077A0F7AD38C61DC2DA6013194%5-7 Min3375%3191%75%2.3.3
133C188488679EDA33700DD3BCB78A2591D9B304A8077A0F7AD38C61DC2DA6014094%3-5 Min33100%4091%100%2.3.3
133C188488679EDA33700DD3BCB78A2591D9B304A8077A0F7AD38C61DC2DA6012094%<= 3 Min33100%2091%100%2.3.3
1 ACCEPTED SOLUTION

Hi, @hsing121 

First, use the following expression to create a calculated table:

Table2 = VALUES('Table'[boot_minutes_duration])

vjianpengmsft_0-1731392190378.png

vjianpengmsft_3-1731392395992.png

 

Create the following measure:

MEASURE =
CALCULATE (
    SUM ( 'Table'[O Success] ),
    ALLEXCEPT ( 'Table', 'Table'[vehicle_id], 'Table'[SubBranch] ),
    FILTER (
        ALL ( 'Table'[boot_minutes_duration] ),
        'Table'[boot_minutes_duration] IN VALUES ( Table2[boot_minutes_duration] )
    )
)
ShowItem =
VAR _1 =
    IF ( ISFILTERED ( Table2[boot_minutes_duration] ), 1, 0 )
RETURN
    IF (
        _1 = 0,
        1,
        IF (
            SELECTEDVALUE ( 'Table'[boot_minutes_duration] )
                IN VALUES ( Table2[boot_minutes_duration] ),
            1,
            0
        )
    )

Next, set up your visuals:

vjianpengmsft_1-1731392355012.png

vjianpengmsft_2-1731392371573.png

Here are the results:

vjianpengmsft_4-1731392431783.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

View solution in original post

13 REPLIES 13
hsing121
Regular Visitor

Thanks @v-jianpeng-msft  its working. i have accepted that as a solution. However, i need to plot it too and use it in x axis, but it being a measure , i m not able to drag it to x axis of a clustered bar chart . any solution for that

hsing121
Regular Visitor

@parry2k i tried that but its not working. i will try to share pbi file or data in sometime

Hi, @hsing121 

Have you tried the solution I provided? As you described, when slicer selection >=7min and 5-7min, 52,59 is displayed:

vjianpengmsft_0-1731633000466.png

 

Best Regards

Jianpeng Li

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

 

parry2k
Super User
Super User

@hsing121 try this measure 

 

Sum = 
CALCULATE (
    CALCULATE ( 
        SUM ( vehicle[O Success] ),
        ALLEXCEPT ( 
            vehicle, 
            vehicle[vehicle_id], 
            vehicle[SubBranch], 
            vehicle[boot_minutes_duration] 
        )
    ), 
    ALLSELECTED ( vehicle[boot_minutes_duration] )
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@hsing121 I don't think you made your file available to download publically, it is asking me to login, can you try again?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

hsing121
Regular Visitor

Hi @parry2k , i am not able to share but let me try explaining more. The below data is at vehicle id, sub branch and boot minutes level. Note the sum column, this is summing up the o success column values at vehicle id and sub branch level , the dax for that is 

CALCULATE(SUM(data_for_pbi[O Success]),ALLEXCEPT(data_for_pbi,data_for_pbi[vehicle_id],data_for_pbi[SubBranch]) )
vehicle_idO SuccessO FailSB%boot_minutes_durationSubBranchsum
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  51098% >7 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  1098%5-7 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  1098%3-5 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  7198%<= 3 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  580100% >7 Min2.0.468
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  10100%5-7 Min2.0.468
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  20100%3-5 Min2.0.468
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  70100%<= 3 Min2.0.468

 

Now , assume i have a boot minutes multi select slicer. i want the sum column to show below values when ">7 min" and "5-7 min" are selected in the slicer. that means , the data should first filter by boot minutes group column and then the sum should be taken at vehicle id and sub branch level 

vehicle_idO SuccessO FailSB%boot_minutes_durationSubBranchsum
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  51098% >7 Min2.0.1052
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  1098%5-7 Min2.0.1052
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  580#### >7 Min2.0.459
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599  10####5-7 Min2.0.459




parry2k
Super User
Super User

@hsing121 your requirement is still not very clear, can you post the data in the excel sheet with the expected output with different scenarios and share that excel sheet using one drive/google drive.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @parry2k , can you try checking this data_for_pbi.csv
basically what i want is that sum of o success column should sum at vehile id and sub branch level but we have a boot minutes group too. each sub branch may have multiple boot minutes group. while summing up the o success column values at sub branch, i want to consider  the slicer selection in boot minutes group but at the same time , i dont want the data to show at boot minutes group level. 

e.g. consider below case and look at sum column

vehicle_idO SuccessO FailSB%boot_minutes_durationSubBranchsum
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 51098% >7 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 1098%5-7 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 1098%3-5 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 7198%<= 3 Min2.0.1060
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 580100% >7 Min2.0.468
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 10100%5-7 Min2.0.468
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 20100%3-5 Min2.0.468
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 70100%<= 3 Min2.0.468

here, if the total sum of o success at sub branch 2.0.10 is 51+1+1+7 = 60 , so when there is no boot minutes selected in boot minutes slicer , the sum column (which i m trying to  derive) should show 60 , but lets say if i select ">7 min" and "5-7 min" , then the table should show only these 2 groups and sum should up as 52 like below

 

vehicle_idO SuccessO FailSB%boot_minutes_durationSubBranchsum
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 51098% >7 Min2.0.1052
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599 1098%5-7 Min2.0.1052



v-jianpeng-msft
Community Support
Community Support

Thank you parry2k 

Hi, @hsing121 

You must create a measure with the following values:

Measure = CALCULATE(SUM('Table'[O Success]),ALLEXCEPT('Table','Table'[boot_minutes_duration],'Table'[vehicle_id]))

This will keep only vehicle_id, boot_minutes_duration as outer filters. Here are the results

vjianpengmsft_0-1731291016261.png

vjianpengmsft_1-1731291067061.png

vjianpengmsft_2-1731291091430.png

I've provided the PBIX file used this time below.

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

I am attaching the same pbi . the same vehicle can exist at multiple subbranches. the boot minutes duration is a level below subbranch. so vehicle id is highest level group, then subbranch and then bootminutes. what i want is , the sum of o success should always be at vehicle and sub branch level. but if a user is selecting a group of boot minutes e.g. >7 min and 5-7 min then the sub branch should be sum of o success for those boots but summed up at sub branch level. 


actually i m not able to attach the pbix file, i dont see option anywhere. attaching screenshot below .
with no slicer selected : 

hsing121_0-1731355957899.png

with slicer selected: 

hsing121_1-1731356036235.png

here i the formula for sum_for_subbranch is 

Sum_for_subbranch = CALCULATE(SUM(data_for_pbi[O Success]),ALLEXCEPT(data_for_pbi,data_for_pbi[vehicle_id],data_for_pbi[SubBranch]) )
but what i want the value to show up as , is 8 for all rows of sub branch 2.0.10 and 9 for all rows of sub branch 2.0.4

below is all data 
vehicle_idO SuccessO FailSB%boot_minutes_durationselectedvalueBD%P SuccessP FailSB%BD%SubBranch
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C572686159951098% >7 Min60100%50197%98%2.0.10
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C57268615991098%5-7 Min60100%1097%100%2.0.10
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C57268615991098%3-5 Min60100%1097%100%2.0.10
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C57268615997198%<= 3 Min6088%7197%88%2.0.10
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C5726861599580100% >7 Min68100%57199%98%2.0.4
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C572686159910100%5-7 Min68100%1099%100%2.0.4
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C572686159920100%3-5 Min68100%2099%100%2.0.4
000538F1391CEFC8438051087B71DE12B90B7AB02C9C2111A7201C572686159970100%<= 3 Min68100%7099%100%2.0.4

 

Hi, @hsing121 

First, use the following expression to create a calculated table:

Table2 = VALUES('Table'[boot_minutes_duration])

vjianpengmsft_0-1731392190378.png

vjianpengmsft_3-1731392395992.png

 

Create the following measure:

MEASURE =
CALCULATE (
    SUM ( 'Table'[O Success] ),
    ALLEXCEPT ( 'Table', 'Table'[vehicle_id], 'Table'[SubBranch] ),
    FILTER (
        ALL ( 'Table'[boot_minutes_duration] ),
        'Table'[boot_minutes_duration] IN VALUES ( Table2[boot_minutes_duration] )
    )
)
ShowItem =
VAR _1 =
    IF ( ISFILTERED ( Table2[boot_minutes_duration] ), 1, 0 )
RETURN
    IF (
        _1 = 0,
        1,
        IF (
            SELECTEDVALUE ( 'Table'[boot_minutes_duration] )
                IN VALUES ( Table2[boot_minutes_duration] ),
            1,
            0
        )
    )

Next, set up your visuals:

vjianpengmsft_1-1731392355012.png

vjianpengmsft_2-1731392371573.png

Here are the results:

vjianpengmsft_4-1731392431783.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

parry2k
Super User
Super User

@hsing121 why it is not a simple sum, why are you using ALLEXCEPT?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.