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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Young_G_Han
Helper III
Helper III

Sales between two different dates but the dates have to be defined by other columns.

  Dear Sir

 

Dax formula is a very difficult but fun tool for a simple user. I admire the Kudos who help the light users, thank you in advance.

 

I need to sum transactions between two dates.

 

But my problem is that I need to apply different periods for each customer.

 

For example,

 

For AAA customer, I have to take the periods from another table but that must be code 'A' and '1'.

Let's say the period should be 01/01/2023 to 01/10/2023. This is already in a period table.

 

For BBB customer, I have to take the periods from the same table but that must be code 'B' and '2'.

Likely said the period should be 01/10/2022 to 01/05/2023. This is also in the period table.

 

 

Following is the table sample.

 

Transactions

 

Customer   Item   Transaction Q'ty  Transaction Date

AAA               a              100              01/05/2023 

AAA               b               10               01/01/2022

BBB                a                5                01/01/2023

BBB                b               20               01/08/2022

 

 

Date

Customer   Start Date       End Date        Code

AAA            01/01/2023    01/10/2023       1

AAA            01/01/2022    31/12/2022       2

BBB             01/10/2022    01/05/2023       1

BBB             01/10/2021    30/09/2022       2

 

 

Probably I need to create a table or I can use a measure that can create table visualization.

 

The result I need is...

 

Customer   Transaction   Item    Code

AAA            100                 a          1

AAA              10                 b          2

BBB               5                   a          1

BBB               20                 b          2

 

 

Is this possible? It is okay whether I need to create a table or a measure.

Please help.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Young_G_Han , You can add Code in table one as a new column and then join these two table

 

Code column in transaction

 

Maxx(filter(Date, Date[Customer] = Transactions[Customer] && Transactions[Transaction Date] >= Date[Start Date] &&  Transactions[Transaction Date] <= Date[End Date] ) , Date[Code])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @Young_G_Han 

 

First you need to create a item/code match in your period/dates table:

Code2 = 
SWITCH ( 'Date'[Code], 1, "a", 2, "b" )

You can then use the calc column formula below to get the sales amount from anothe table based on a certain start and end dates:

Qty = 
CALCULATE (
    SUM ( Sales[Transaction Qty] ),
    FILTER (
        Sales,
        Sales[Transaction Date] >= EARLIER ( 'Date'[Start Date] )
            && Sales[Transaction Date] <= EARLIER ( 'Date'[End Date] )
            && 'Sales'[Customer] = EARLIER ( 'Date'[Customer] )
            && Sales[Item] = EARLIER ( 'Date'[Code2] )
    )
)

danextian_0-1697770926042.png

Please see attached pbix for reference.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

  Dear Sir

 

Thank you. This is very helpful me to understand date and add column.

amitchandak
Super User
Super User

@Young_G_Han , You can add Code in table one as a new column and then join these two table

 

Code column in transaction

 

Maxx(filter(Date, Date[Customer] = Transactions[Customer] && Transactions[Transaction Date] >= Date[Start Date] &&  Transactions[Transaction Date] <= Date[End Date] ) , Date[Code])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

  Dear Sir

 

It is working finely. I could add more columns as filter, this is very useful.

 

Thank you very much.

 

Regards,

Young.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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