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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
dospencer
Frequent Visitor

Calculated Measure gives different result when I use a column vs a calculated column in the formula

I have a calculated column that is concatenating a code and a title in a table as below:
Organization = SWITCH(TRUE(), 'DWH Finance_Organization_Dim'[Organization_Code] IN {"FA","NETTUI","PCTDIS","SA","TUIREV"},'DWH Finance_Organization_Dim'[Title],'DWH Finance_Organization_Dim'[Organization_Code]&" "&'DWH Finance_Organization_Dim'[Title])
 
I also have a measure defined that I use in a matrix visual but I get different results when I use the "Organization" calculated column vs the "Title" column in the Matrix visual.
 
When the measure is defined as shown below and I use the "Title" column in the visual, I get the correct results but when I use "Organization" in the visual I get 0. I have even replaced Title with "Organization" in the CALCULATE filter and still doesn't work:
_subtotalNetTuition =
CALCULATE(SUM('ODS Net_Tuition'[Tuition_Billed])
, ALL('DWH Finance_Organization_Dim'[Title])
,'DWH Finance_Organization_Dim'[Line_Order] <= 5)
 
What am I doing wrong?
1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @dospencer 

Try to modify your measure like this:

__Selected Measure = 
VAR _maxline =
    MAX ( 'DWH Finance_Organization_Dim'[Line_Order] )
VAR _subtotalTuitionRevenue =
    CALCULATE (
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] ),
        // ALL( 'DWH Finance_Organization_Dim'[Title]),
        ALL( 'DWH Finance_Organization_Dim'),
        'DWH Finance_Organization_Dim'[Line_Order] <= 3
    )
VAR _subtotalNetTuition =
    CALCULATE (
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] ),
        // ALL ( 'DWH Finance_Organization_Dim'[Title] ),
        ALL ( 'DWH Finance_Organization_Dim' ),
        'DWH Finance_Organization_Dim'[Line_Order] <= 5
    )
VAR _subtotalFinancialAid =
    CALCULATE (
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] ),
        ALL ( 'DWH Finance_Organization_Dim' ),
        // 'DWH Finance_Organization_Dim'[Title] = "Financial Aid Awards"
        'DWH Finance_Organization_Dim'[Title] = "Financial Aid"
    )
VAR _percentDiscount =
    DIVIDE ( _subtotalFinancialAid, _subtotalTuitionRevenue, 0 )
VAR _subtotal =
    SWITCH (
        TRUE (),
        _maxline = 3, _subtotalTuitionRevenue,
        // _maxline = 4, _subtotalFinancialAid * -1,
        _maxline = 4, _subtotalFinancialAid * 1,
        _maxline = 5, _subtotalTuitionRevenue - _subtotalFinancialAid,
        _maxline = 6
            && NOT ISBLANK ( _percentDiscount ), FORMAT ( _percentDiscount, "Percent" ),
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] )
    )
RETURN
    _subtotal

Result:

 

vangzhengmsft_0-1648531023814.png

Please refer to the attachment below for details.

You can read the following blog to learn more about the ALL function
https://radacad.com/how-to-use-all-in-a-dax-expression-in-power-bi

https://blog.enterprisedna.co/how-to-use-the-all-function-in-power-bi-dax/

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

4 REPLIES 4
v-angzheng-msft
Community Support
Community Support

Hi, @dospencer 

Try to modify your measure like this:

__Selected Measure = 
VAR _maxline =
    MAX ( 'DWH Finance_Organization_Dim'[Line_Order] )
VAR _subtotalTuitionRevenue =
    CALCULATE (
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] ),
        // ALL( 'DWH Finance_Organization_Dim'[Title]),
        ALL( 'DWH Finance_Organization_Dim'),
        'DWH Finance_Organization_Dim'[Line_Order] <= 3
    )
VAR _subtotalNetTuition =
    CALCULATE (
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] ),
        // ALL ( 'DWH Finance_Organization_Dim'[Title] ),
        ALL ( 'DWH Finance_Organization_Dim' ),
        'DWH Finance_Organization_Dim'[Line_Order] <= 5
    )
VAR _subtotalFinancialAid =
    CALCULATE (
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] ),
        ALL ( 'DWH Finance_Organization_Dim' ),
        // 'DWH Finance_Organization_Dim'[Title] = "Financial Aid Awards"
        'DWH Finance_Organization_Dim'[Title] = "Financial Aid"
    )
VAR _percentDiscount =
    DIVIDE ( _subtotalFinancialAid, _subtotalTuitionRevenue, 0 )
VAR _subtotal =
    SWITCH (
        TRUE (),
        _maxline = 3, _subtotalTuitionRevenue,
        // _maxline = 4, _subtotalFinancialAid * -1,
        _maxline = 4, _subtotalFinancialAid * 1,
        _maxline = 5, _subtotalTuitionRevenue - _subtotalFinancialAid,
        _maxline = 6
            && NOT ISBLANK ( _percentDiscount ), FORMAT ( _percentDiscount, "Percent" ),
        SUM ( 'ODS Net_Tuition'[Tuition_Billed] )
    )
RETURN
    _subtotal

Result:

 

vangzhengmsft_0-1648531023814.png

Please refer to the attachment below for details.

You can read the following blog to learn more about the ALL function
https://radacad.com/how-to-use-all-in-a-dax-expression-in-power-bi

https://blog.enterprisedna.co/how-to-use-the-all-function-in-power-bi-dax/

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

v-angzheng-msft
Community Support
Community Support

Hi, @dospencer 

Could you please consider sharing more details about it and posting expected result so it is clear on what needs to be implemented?  And It would be great if there is a sample file without any sesentive information here.

It makes it easier to give you a solution.

  1. Sample (dummy dataset) data as text, use the table tool in the editing bar
  2. Expected output from sample data
  3. Explanation in words of how to get from 1. to 2.

 

 

Best Regards,
Community Support Team _ Zeon Zheng

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

@v-angzheng-msft ,

 

Thank you.

 

Here's the additional information you requested. 

The Dimension table: DWH Finance_Organization_Dim

Organization_KeyOrganization_CodeTitleLine_Order
1210

 

Undergraduate Tuition & Fees

1
2SAStudy Abroad2
3TUIREVTuition Revenue3
4FAFinancial Aid4
5NETTUINet Tuition5
6PCTDISCPercent Discount6

 

The fact table: ODS Net_Tuition

CollegeTermOrganization_KeyFiscal_YearTuition_Billed
My CollegeFall12022200
My CollegeFall12021300
My CollegeFall12022400
My CollegeFall22022100
My CollegeFall2202150
My CollegeFall42022100
My CollegeFall42022100
My CollegeFall320220
My CollegeFall520220
My CollegeFall620220
My CollegeFall320210
My CollegeFall520210
My CollegeFall620210

 

The tables are joined via the Organization_Key column.

 

Expected results with the "Organization" calculated column:

My College 
   Fall 2022 
      210 - Undergraduate Tuition & Fees$600
      Study Abroad$100
      Tuition Revenue$700 
      Financial Aid$200
      Net Tuition$500 
      Percent Discount28.57%
   Spring 2022 
      ... 

 

Actual results with the "Organization" calculated column:

My College 
   Fall 2022 
      210 - Undergraduate Tuition & Fees$600
      Study Abroad$100
      Tuition Revenue$0
      Financial Aid$200
      Net Tuition$500 
      Percent Discount0.0%
   Spring 2022 

 

Here's the DAX for the measure that is placed in the visual and works if i use the Title in Rows of the visual but doesn't work if I use the Organization calculated column:

Selected Measure =
VAR _maxline =
MAX ('DWH Finance_Organization_Dim'[Line_Order] )

VAR _subtotalTuitionRevenue =
CALCULATE(SUM('ODS Net_Tuition'[Tuition_Billed])
, ALL('DWH Finance_Organization_Dim'[Title])
,'DWH Finance_Organization_Dim'[Line_Order] <= 3)
    
VAR _subtotalNetTuition =
CALCULATE(SUM('ODS Net_Tuition'[Tuition_Billed])
, ALL('DWH Finance_Organization_Dim'[Title])
,'DWH Finance_Organization_Dim'[Line_Order] <= 5)

VAR _subtotalFinancialAid =
CALCULATE(SUM('ODS Net_Tuition'[Tuition_Billed])
, ALL('DWH Finance_Organization_Dim')
,'DWH Finance_Organization_Dim'[Title] = "Financial Aid Awards")

VAR _percentDiscount =
DIVIDE(_subtotalFinancialAid,_subtotalTuitionRevenue,0)
 

VAR _subtotal =
SWITCH(TRUE(),

     _maxline = 3, _subtotalTuitionRevenue
     ,_maxline = 4, _subtotalFinancialAid*-1
        ,_maxline = 5, _subtotalTuitionRevenue - _subtotalFinancialAid
        ,_maxline = 6 && NOT ISBLANK ( _percentDiscount ),
            FORMAT ( _percentDiscount, "Percent" )
        ,SUM('ODS Net_Tuition'[Tuition_Billed])
        )

RETURN _subtotal
johnt75
Super User
Super User

Use Performance Analyzer to get the DAX generated for the visual and compare between the versions which use Title and Organization. It is possible that more filters are being applied when you use Organization, perhaps for a sort by column, and you may need to remove those as well as the filter on Organization.

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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