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

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

Reply
Evelin_
Helper I
Helper I

DAX calculate with multiple criteria

Hello, I would like to have a measure where I want to calculate a share for actual and for Target, and then I want to highlight the difference between them. For the share I have to get from the database 2 VAR, 1 with 1 filter but the other one with 2 filter like this:
 
VAR 1BP=
Calculate(
    SUM(Database[Volume in UC]),
    Filter(
        Database,
         Database[Version] = "BP"
        && Database[xxx] = "SS"
    )
VAR 2BP=
Calculate(
    SUM(Database[Volume in UC]),
         Database[Version] = "BP"
    )
VAR 3 SHARE=
divide (VAR1BP , VAR2BP , -1) ---> here I should get something like 68% (it should be under 100%)
 
VAR 1ACT=
Calculate(
    SUM(Database[Volume in UC]),
    Filter(
        Database,
         Database[Version] = "ACT"
        && Database[xxx] = "SS"
    )
VAR 2ACT=
Calculate(
    SUM(Database[Volume in UC]),
         Database[Version] = "ACT"
    )
VAR 4 SHARE=
divide (VAR1ACT , VAR2ACT , -1) ---> here I should get something like 68% (it should be under 100%)
 VAR 5 = VAR 3 SHARE - VAR 4 SHARE 
 
How Can I write this dax properly? I think I wont have problem with the RETURN part, I have problem with the VAR parts.
Thank you in advance!
 
3 ACCEPTED SOLUTIONS

@Evelin_ From the DAX code I can spot couple of mistakes. You are using Database table reference inside CALCULATE which is respecting the existing Filter Context so before it can be filtered for BP and SS it already gets filtered by whatever is the active Filter Context and the table returned by FILTER will be empty, try this instead:

 

CALCULATE (
    SUM ( Database[Volume in UC] ),
    Database[Version] = "BP"
        && Database[xxx] = "SS"
)

 

The above will ensure it ignores the existing Filter context on these 2 columns.

 

And if you don't want to overwrite the existing filter context on Version and XXX then use this:

 

CALCULATE (
    SUM ( Database[Volume in UC] ),
    KEEPFILTERS ( Database[Version] = "BP" && Database[xxx] = "SS" )
)

 

 

View solution in original post

FreemanZ
Super User
Super User

hi @Evelin_ ,

 

try like:

Measure =

VAR 1BP=

Calculate(

    SUM(Database[Volume in UC]),

    Filter(

        Database,

         Database[Version] = "BP"

        && Database[xxx] = "SS"

    )

VAR 2BP=

Calculate(

    SUM(Database[Volume in UC]),

         Database[Version] = "BP"

    )

VAR 3SHARE= divide (1BP , 2BP ) - 1

RETURN 3SHARE

View solution in original post

Dangar332
Super User
Super User

@Evelin_ 
You need to use Dax Formatter 

 

VAR BP_1 =
    CALCULATE (
        SUM ( Database[Volume in UC] ),
        FILTER ( Database, Database[Version] = "BP" && Database[xxx] = "SS" )
    )
VAR BP_2 =
    CALCULATE ( SUM ( Database[Volume in UC] ), Database[Version] = "BP" )
VAR SHARE_3 =
    DIVIDE ( BP_1, BP_2, -1 )
VAR ACT_1 =
    CALCULATE (
        SUM ( Database[Volume in UC] ),
        FILTER ( Database, Database[Version] = "ACT" && Database[xxx] = "SS" )
    )
VAR ACT_2 =
    CALCULATE ( SUM ( Database[Volume in UC] ), Database[Version] = "ACT" )
VAR SHARE_4 =
    DIVIDE ( ACT_1, ACT_2, -1 )
RETURN
    SHARE_3 - SHARE_4

 

 

Best Regards,
Dangar

 

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

6 REPLIES 6
Dangar332
Super User
Super User

@Evelin_ 
You need to use Dax Formatter 

 

VAR BP_1 =
    CALCULATE (
        SUM ( Database[Volume in UC] ),
        FILTER ( Database, Database[Version] = "BP" && Database[xxx] = "SS" )
    )
VAR BP_2 =
    CALCULATE ( SUM ( Database[Volume in UC] ), Database[Version] = "BP" )
VAR SHARE_3 =
    DIVIDE ( BP_1, BP_2, -1 )
VAR ACT_1 =
    CALCULATE (
        SUM ( Database[Volume in UC] ),
        FILTER ( Database, Database[Version] = "ACT" && Database[xxx] = "SS" )
    )
VAR ACT_2 =
    CALCULATE ( SUM ( Database[Volume in UC] ), Database[Version] = "ACT" )
VAR SHARE_4 =
    DIVIDE ( ACT_1, ACT_2, -1 )
RETURN
    SHARE_3 - SHARE_4

 

 

Best Regards,
Dangar

 

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



FreemanZ
Super User
Super User

hi @Evelin_ ,

 

try like:

Measure =

VAR 1BP=

Calculate(

    SUM(Database[Volume in UC]),

    Filter(

        Database,

         Database[Version] = "BP"

        && Database[xxx] = "SS"

    )

VAR 2BP=

Calculate(

    SUM(Database[Volume in UC]),

         Database[Version] = "BP"

    )

VAR 3SHARE= divide (1BP , 2BP ) - 1

RETURN 3SHARE

AntrikshSharma
Super User
Super User

"How Can I write this dax properly?" What kind of help do you need here? Optimization or the results are incorrect?

Hello! 

the result is incorrect and I tried to fix it but I think I miss something, some digns or anything that can cause error 😞

 

Thank you for your answer!

Evelin

@Evelin_ From the DAX code I can spot couple of mistakes. You are using Database table reference inside CALCULATE which is respecting the existing Filter Context so before it can be filtered for BP and SS it already gets filtered by whatever is the active Filter Context and the table returned by FILTER will be empty, try this instead:

 

CALCULATE (
    SUM ( Database[Volume in UC] ),
    Database[Version] = "BP"
        && Database[xxx] = "SS"
)

 

The above will ensure it ignores the existing Filter context on these 2 columns.

 

And if you don't want to overwrite the existing filter context on Version and XXX then use this:

 

CALCULATE (
    SUM ( Database[Volume in UC] ),
    KEEPFILTERS ( Database[Version] = "BP" && Database[xxx] = "SS" )
)

 

 

Many many thanks, it worked!!

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.