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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
andrew_bouland
Frequent Visitor

Measure to show zero if fact table contains no value for date and location

I am working on a report to show the number of employees that are present in a given location by date.

I have a fact Table 'CheckinDaily' has columns for Date, Location, Users and it only contains values where the Users count is 1 or greater.  I would like to be able to create a measure/custom column to show values for all possible locations for any given date where Users value is 0 if there is not an entry in the fact table for that location for a date. 

Fact table is related to a date table 'Date' many to one that has values for every calendar date from 2020-2030

 

Fact table is also related many to one to a Location table 'OfficeAbbr' that has values for all of our various offices


Fact table example:

DateLocationUsers
1/28/2025ATL1
1/28/2025STL20
1/29/2025DEC2
1/29/2025SPG4
1/30/2025DAL25

 

Location table example:

 

Location
ATL
BOS
BOS2
CHT
CIN
COS
DAL
DEC
DEN
SPG
STL


What I'd like to see:

1/28/2025ATL1
1/28/2025BOS0
1/28/2025BOS20
1/28/2025CHT0
1/28/2025CIN0
1/28/2025COS0
1/28/2025DAL0
1/28/2025DEC0
1/28/2025DEN0
1/28/2025SPG0
1/28/2025STL20
1/29/2025ATL0
1/29/2025BOS0
1/29/2025BOS20
1/29/2025CHT0
1/29/2025CIN0
1/29/2025COS0
1/29/2025DAL0
1/29/2025DEC2
1/29/2025DEN0
1/29/2025SPG4
1/29/2025STL0

etc

I have tried the following meaure:

 

Daily Headcount by Location =

IF (

    CALCULATE(COUNTROWS('CheckinDaily'), 'CheckinDaily'[Date] = ('Date'[Date]), 'CheckinDaily'[Location] = ('Location'[Location])) = 0,

    0,

    SUM('CheckinDaily'[Users])

)


when attempting to create the measure, I get an error: 

 

"The expression contains columns from multiple tables, but only columns from a single table can be used in a True/False expression that is used as a table filter expression."

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @andrew_bouland 

You can try the following dax to achieve your need.

vyaningymsft_0-1739499457042.png

Note that your table one has blank data rows, which will affect your output, so it's best to optimize your data.

vyaningymsft_1-1739499495350.png

Table 2 = 
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT('Table 1'[Date]),
        'Location'
    ),
    "Users", 
    VAR CurrentDate = [Date]
    VAR CurrentLocation = 'Location'[Location]
    RETURN
    CALCULATE(
        SUM('Table 1'[Users]) + 0,
        'Table 1'[Date] = CurrentDate,
        'Table 1'[Location] = CurrentLocation
    )
) 


Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. 
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi, @andrew_bouland 

Based on the information you gave, you can try the following dax to achieve your need, if this doesn't fit your needs, you can give pbix files without sensitive data for testing (it seems you have Date table in your raw data).


vyaningymsft_1-1739329438425.png

 

 

NewTable 2 = 
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT('Table 1'[Date]),
        'Table 2'
    ),
    "Users", 
    VAR CurrentDate = [Date]
    VAR CurrentLocation = [Location]
    RETURN
    CALCULATE(
        SUM('Table 1'[Users]),
        'Table 1'[Date] = CurrentDate,
        'Table 1'[Location] = CurrentLocation
    )
)

 

 

Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hello, thank you for the suggestion - having a little trouble still - getting an error with the VAR statements at the moment.  If I don't specify table for Location then it tells me it cannot find Location reference.  If I do specify table for Date and/or location then I get an error "A single value for column 'Date' in table 'Date' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

Here's current code I am trying:

Table 2 =
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT('Table 1'[Date]),
        'Table 2'
    ),
    "Users",
    VAR CurrentDate = 'Date'[Date]
    VAR CurrentLocation = 'Location'[Location]
    RETURN
    CALCULATE(
        SUM('Table 1'[Users]),
        'Table 1'[Date] = CurrentDate,
        'Table 1'[Location] = CurrentLocation
    )
) +0

 
pbix same file here

Posted this before seeing your PBIX example - in my case we've got a discrete date table that we're referencing as our fact table (table 1) might have gaps where a calendar date has no value(s) present.  We'd want to make sure that we're getting zeros for any calendar date per location where there isn't a value reported in our fact table for that specific date. 

Anonymous
Not applicable

Hi, @andrew_bouland 

You can try the following dax to achieve your need.

vyaningymsft_0-1739499457042.png

Note that your table one has blank data rows, which will affect your output, so it's best to optimize your data.

vyaningymsft_1-1739499495350.png

Table 2 = 
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT('Table 1'[Date]),
        'Location'
    ),
    "Users", 
    VAR CurrentDate = [Date]
    VAR CurrentLocation = 'Location'[Location]
    RETURN
    CALCULATE(
        SUM('Table 1'[Users]) + 0,
        'Table 1'[Date] = CurrentDate,
        'Table 1'[Location] = CurrentLocation
    )
) 


Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. 
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thanks so much, I was able to get it working as I needed!

 

Andrew

Hi,

 

I would just add a little something to your formula to answer exactly the question :

Add +0 by the end of formula if you want 0 and not blank as a result.

Thanks for your answer

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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