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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
G_Whit-UK
Helper II
Helper II

Count of number of transactions per region, per day

Hi,

I'm working in Power BI and need some help with a measure to calculate the number of transactions per day, per region.  The data set has two key tables ("Date" and "Global Failing Sales Data").  The simplified table structure is as follows:

 

Date Table:

Date
01 April 2023
02 April 2023
03 April 2023
04 April 2023
05 April 2023
06 April 2023
07 April 2023
08 April 2023
09 April 2023

 

Global Failing Sales Data:

DateRegionTrade Ref
01 April 2023EMEA12345
01 April 2023EMEAABC123
01 April 2023AmericasABCDE
02 April 2023EMEA12345
02 April 2023AmericasXYZ
04 April 2023EMEA9872
08 April 2023AmericasCHT123
08 April 2023AmericasNVC456
08 April 2023AmericasJKD765
08 April 2023EMEAxd1562

 

The "Dates" has a date for every day within the reporting period (& beyond).  Therefore this is the best source for the dates.  The "Global Failing Sales" table only has records for dates which has activity.  Therefore there are some gaps in the date range.

 

Example of current DAX formulae:

 

 

 

Americas Failing Sales = 
CALCULATE (
    DISTINCTCOUNTNOBLANK ( 'Global Failing Sales Data'[Trade Ref] ),
    'Global Failing Sales Data'[Region] = "Americas"
)

 

 

 

 

The problem I need to solve is that the above DAX formula doesn't return a zero value for dates which do not have any failing sales data (due to gaps in the Global Failing Sales date range).  Ultimately I want to be able to create a chart to be something like the following (based on the above dummy data):

G_WhitUK_0-1682410913136.png

 

What is the correct measure which uses the dates from the Dates table, and the transaction count from the Global Failing Sales table?

 

(FYI:  It doesn't help if I amend the existing formula to "DISTINCTCOUNT")

1 ACCEPTED SOLUTION

Thanks again @johnt75 for your input.  The link you suggested in your original reply pointed me in the correct direction.  The issue was resolved by amending the DAX to be as follows:

Americas Failing Sales = 
VAR Raw_Count =
    CALCULATE (
        DISTINCTCOUNT ( 'Global Failing Sales Data'[Trade Ref] ),
        'Global Failing Sales Data'[Region] = "Americas"
    )
VAR Adj_Count = Raw_Count + 0
RETURN
    Adj_Count

View solution in original post

6 REPLIES 6
mw72
New Member

Hi G_Whit_UK,

 

Could a simple solution be to

1) right click on the Date field and choose to 'Show items with no data'.

mw72_0-1682457256665.png

 

2) use a bar chart instead of a line chart?

 

mw72_1-1682457285360.png

 

 

 

Ajendra
Resolver I
Resolver I

Hello,  Try This!

 

Measure =
VAR _Date = MAX(DateMaster[Date])
VAR _Result  = COUNTROWS(FILTER(FactTable,FactTable[Date]<=_Date))
return
if(_Result <1,0,_Result)
 
1.JPG
johnt75
Super User
Super User

There's a couple of ways of tackling this. The simplest way is to simply add 0 to your existing measure, but that will return 0 for every date in your date table, even dates before the first ever transaction and after the last ever transaction. You might be able to work around that by putting filters onto the charts, or you might want to only return 0 for dates where it was possible for there to be a transaction, in which case check out https://www.sqlbi.com/articles/how-to-return-0-instead-of-blank-in-dax/ 

Thanks @johnt75 for the suggestion.  I was thinking along the same lines, but was wondering if there is a smarter way of achieving this.  Do you know if there is a way in which I can add the "missing" dates (gaps) into the Global Failing Sales table by somehow importing dates from the Dates table?

Don't think I'd recommend that, I think it would be a lot messier than the other options. You'd have to do something along the lines of getting all date-region combinations from your data and comparing that to a crossjoin of all possible date-region combinations. Then for every combination that is missing you would need to generate a row whose structure exactly matches the data table and finally union the generated table with the data. And if there were additional dimensions underneath region, e.g. state, then you'd need to include those as well.

Thanks again @johnt75 for your input.  The link you suggested in your original reply pointed me in the correct direction.  The issue was resolved by amending the DAX to be as follows:

Americas Failing Sales = 
VAR Raw_Count =
    CALCULATE (
        DISTINCTCOUNT ( 'Global Failing Sales Data'[Trade Ref] ),
        'Global Failing Sales Data'[Region] = "Americas"
    )
VAR Adj_Count = Raw_Count + 0
RETURN
    Adj_Count

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors