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
DAXRichArd
Resolver I
Resolver I

CALCULATE produces a blank result

 

AirportDAXRelationships.JPGSchedule.jpgResults.JPG

 

Images:

AirportDAXRelationships = screen shot of my data model

Schedule = screen shot of the table this measure is being used in

Results = screen shot of the results I'm getting

 

DAX Functions / Expressions

Refer to "Results" screen shot

 

NOTE: All that follow are written as measure

 

TEST HAS Seats =
CALCULATE (
SUM ( 'Schedule Dynamic Table Report'[Seats] ),
ALL ( 'Schedule Dynamic Table Report'[Origin Code] ),
'Schedule Dynamic Table Report'[Origin Code] = "HOU",
'Schedule Dynamic Table Report'[Origin Code] = "IAH"
)

 

This produces blanks

 

 

TEST HOU Seats =
CALCULATE (
SUM ( 'Schedule Dynamic Table Report'[Seats] ),
ALL ( 'Schedule Dynamic Table Report'[Origin Code] ),
'Schedule Dynamic Table Report'[Origin Code] = "HOU"
)

 

This produces a correct result

 

 

TEST IAH Seats =
CALCULATE (
SUM ( 'Schedule Dynamic Table Report'[Seats] ),
ALL ( 'Schedule Dynamic Table Report'[Origin Code] ),
'Schedule Dynamic Table Report'[Origin Code] = "IAH"
)

 

This produces a correct result

 

 

 

TEST IAH no ALL Seats =
CALCULATE (
SUM ( 'Schedule Dynamic Table Report'[Seats] ),
'Schedule Dynamic Table Report'[Origin Code] = "IAH"
)

 

This produces a correct result.  Here I removed ALL (I initially added ALL to solve my problem then tested it by removing all).

 

 

Software Platform

PowerBI Desktop

 

SUMMARY

I work with commercial airline data. A characteriestic of this data is that it has geographic direction. Simplified, there is out bound or departure data, and there is in bound or arrival data. Depending on what I'm trying to analyze, I look at one direction, or the other, or both combined.

 

Problem Statement

  • I want to analyze departure seats for two airports: 1) IAH, and 2) HOU. Both airports are within the metro city of Houston, Texas.
  • I want to analyze them separately and combined (how do each perform independantly , and how do the City's combined airports perform?).
  • The quantity I'm analyzing is 'seats' (seats are a measure of inventory (each seat can sell for 'x' (a.k.a. air fare).

Partial Solution

  • When I use the CALCULATE fuction and filter for one airport code, the DAX code works and provides a correct result for what I intend it to do.
  • When I write the same code but add a second filter (i.e. filter for IAH and filter for HOU), I get a blank result. Here the formula bar accepts my input and does not return an error message.
    • Refer to the first formula 'TEST HAS Seats'.

Thank you in advance for your help!

 

DAXRichard

Houston, Texas

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @DAXRichArd,

 

One thing to keep in mind when using the filter in the CALCULATE function is that it makes the AND option so when you are calculating both "HOU" / "IAH" the filter is looking for Origin codes that have both values at once you need to chan ge this to an OR, in this case the measure should look like this:

 

 

TEST HAS Seats =
CALCULATE (
    SUM ( 'Schedule Dynamic Table Report'[Seats] ),
    'Schedule Dynamic Table Report'[Origin Code] = "HOU"
        || 'Schedule Dynamic Table Report'[Origin Code] = "IAH"
)

 

This will go to the Origin Code and check if the value is HOU or IAH.

 

The ALL syntax makes your measure ignoring the filters and making the calculations for the full dataset, if you add the ALL and then want to get the HOU with a filter on other column you would always get the total result.

 

Hope this helps and if you need any additonal explanation I will try to assist.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @DAXRichArd,

 

One thing to keep in mind when using the filter in the CALCULATE function is that it makes the AND option so when you are calculating both "HOU" / "IAH" the filter is looking for Origin codes that have both values at once you need to chan ge this to an OR, in this case the measure should look like this:

 

 

TEST HAS Seats =
CALCULATE (
    SUM ( 'Schedule Dynamic Table Report'[Seats] ),
    'Schedule Dynamic Table Report'[Origin Code] = "HOU"
        || 'Schedule Dynamic Table Report'[Origin Code] = "IAH"
)

 

This will go to the Origin Code and check if the value is HOU or IAH.

 

The ALL syntax makes your measure ignoring the filters and making the calculations for the full dataset, if you add the ALL and then want to get the HOU with a filter on other column you would always get the total result.

 

Hope this helps and if you need any additonal explanation I will try to assist.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



AkhilAshok
Solution Sage
Solution Sage

I think you want to use IN. If you specify it as a seperate condition, it acts as an AND. Since one row cannot have both codes, it won't return any results. Another thing is you don't need to explicitly clear the filter context of Origin Code using ALL. If you simply specify the filter as CALCULATE parameter, it automatically clears the filter context on that column.

 

TEST HAS Seats =
CALCULATE (
    SUM ( 'Schedule Dynamic Table Report'[Seats] ),
    'Schedule Dynamic Table Report'[Origin Code] IN {"HOU", "IAH"}
)

 

Ah... I knew that....  No, not really.  Before coming to the forum I read, and read, and researched. I must have glazed over that.

BIG THANK YOU FOR YOUR HELP!  Now I can stop using my stress reduction tool (see attached image).

StressReductionTool.JPG

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.