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
SR_2021
Frequent Visitor

DAX Count Customers based on a MTD measure

I have successfully created two measures

1) Sales MTD; and

2) Sales Prior Month to date

 

I want to

a) count how many customers have been sold to so far this month; and

b) count how many customers had been sold to at the same time last month

 

There is a relationship between Customers (DIM table) and Sales (FACT table)

 

Can anyone help with this as I have tried various combinations with countrow, counta, countif functions but with no luck.

2 REPLIES 2
SR_2021
Frequent Visitor

Thanks for this reply - which I think will help me solve a different challenge 🙂

Adamboer
Responsive Resident
Responsive Resident

To count the number of unique customers sold to so far this month and at the same time last month, you can use the following DAX formulas:

  1. To count the number of unique customers sold to so far this month:

    Customers This Month =
    DISTINCTCOUNT(Sales[Customer ID], FILTER(Sales, YEAR(Sales[Date]) = YEAR(TODAY()) && MONTH(Sales[Date]) = MONTH(TODAY())))


    Explanation:

    • The FILTER function filters the sales table to only include sales that occurred in the current month (using YEAR(TODAY()) and MONTH(TODAY()) functions).
    • The DISTINCTCOUNT function then counts the number of unique customers in the filtered sales table.
    1. To count the number of unique customers sold to at the same time last month:

      Customers Last Month =
      CALCULATE(DISTINCTCOUNT(Sales[Customer ID]),
      DATESYTD(DATEADD(TODAY(), -1, MONTH)),
      ALLSELECTED(Sales))

      Explanation:

      • The DATESYTD function returns a set of dates for the same time period as the current year-to-date, but for the previous month.
      • The DATEADD function subtracts one month from the current date.
      • The CALCULATE function then filters the Sales table to only include sales that occurred during this time period.
      • The DISTINCTCOUNT function counts the number of unique customers in the filtered sales table.

      Note: Make sure to replace Sales[Customer ID] with the actual name of your customer ID column in the Sales table.





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.