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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
paulsnet1986
Helper I
Helper I

Count Transactions If Transaction's Date Range Fell Within Calendar Month

 

I have two tables: a table with customers active in a calendar month and a table of transactions with start and end dates. I want to make a Power BI table that lists the customers and, when filtered by a calendar month, counts the number of transactions that were running during any part of the calendar month. I cannot think of how to do this because I need to link the tables by both customer number and dates? Any help would be appreciated!

 

Table 1

Calendar MonthCustomer ID
3/1/20231111
3/1/20232222
3/1/20233333
3/1/20234444
4/1/20232222
4/1/20233333
4/1/20234444
4/1/20235555
4/1/20236666

 

Table 2

TransactionCustomerStart DateEnd Date
122221/1/2023 
222221/15/20233/15/2025
322221/18/20232/27/2023
433333/12/20236/11/2023
533334/10/2023 
611111/1/2023 

 Desired Result:

Selected Month Filter: March 2023

CustomerTransaction Count
11111
22222
33331
44440
3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

What is the use of Calendar Month name column in Table1?  Also, for 2222, why should the answer be 2.  In March 2023, that Customer appeared only once.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ThxAlot
Super User
Super User

txn cnt.pbix

 

ThxAlot_0-1696723543427.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Deepak_22
Helper I
Helper I

Hello @paulsnet1986 ,To achieve the desired result follow the below steps.

 

Load Data:

Load both Table 1 and Table 2 into Power BI.

Relationships:

Navigate to the "Model" view.

Create a relationship between Table 1and  Table 2 based on the Customer ID column.

New Measure:

In Table 1, create a new measure for counting the number of transactions. The logic should check if the transaction's start and end dates fall within the selected calendar month.

Here's a possible DAX formula for the measure

Transaction Count = 
COUNTROWS(
    FILTER(
        'Table 2',
        'Table 2'[Start Date] <= MAX('Table 1'[Calendar Month]) &&
        OR(
            ISBLANK('Table 2'[End Date]),
            'Table 2'[End Date] >= MIN('Table 1'[Calendar Month])
        )
    )
)

 

Visualization:

Go to the "Report" view.

Drag and drop a table visualization into the report canvas.

Add Customer IDfrom Table 1 and the Transaction Count measure to the table.

Apply a slicer visualization for the Calendar Month from Table 1 to filter by month.

 

This solution will provide a table that lists customers and, when filtered by a calendar month, counts the number of transactions that were running during any part of that calendar month

 

If you find this helpful, please provide a kudo and mark it as an accepted solution.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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