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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
l0ganBI
Frequent Visitor

DAX Measure : SUMIF Next Sale Month not equal to Transaction Month

Hello,

I have three tables

 

Inventory

Id
0001
0002
0003

 

Sales

Inventory Id Sale Date Quantity
0001 10/01/20 15
0002 10/02/20 10
0003 10/03/20 20
0001 10/04/20 5
0002 09/02/20 5
0003 10/05/20 20
0001 11/11/20 15

 

Transaction Log

Inventory Id Transaction Date
0001 09/30/20
0002 09/29/20
0003 10/01/20
0001 10/02/20
0002 08/31/20
0003 10/01/20
0001 10/31/20

 

Here are my relationships

Inventory     Sales

Id   1:* Inventory ID

Inventory   Transaction log

Id   1:* Inventory ID

 

How do I write a measure that will give me the total quantity sold where the transaction month is not equal to the following sale month? I want the result to be this:

 

Inventory Id QuantityTransaction Date Sale Date
0001 1509/30/20 10/01/20
0002 1009/29/20 10/02/20
0002 508/31/20 09/02/20
0001 1510/31/20 11/11/20

 

Thank you in advance for any help or guidance!!

5 REPLIES 5
wdx223_Daniel
Super User
Super User

you can not get what you want depending on the sample data.

a key column should be add in the sales table and transaction log table to defind for each row in sales which row of the transaction log table is its correspondence

 

Thanks for your recommendation @wdx223_Daniel. I managed to rebuild my data model where it includes the transaction date and sale date in the same table.

edhans
Super User
Super User

I'm not sure I fully understand your question @l0ganBI - take a look at this:

edhans_0-1612314103428.png

This measure returns the quantity where the current month isn't equal to next month, but it requires time intelligence and thus a date table. 

Total Quantity = 
VAR varCurrentMonth = MAX('Date'[Month Year Sort])
VAR varNextMonth = 
    CALCULATE(
        MAX('Date'[Month Year Sort]),
        NEXTMONTH('Date'[Date])
    )
VAR RESULT = 
    CALCULATE(
        SUM(Sales[Quantity]),
        FILTER(
            'Date',
            'Date'[Month Year Sort] <> varNextMonth
        )
    )
RETURN
RESULT

My PBIX file is here if you want to take a look at it.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hello @edhans . Thank you for your reply and I apologize if my post is not very clear. I managed to get the transcation date and the sale date columns into the same table which should help clarify what I am trying to accomplish. I will repost this and tag you if you wish to continue helping me out. Your measure looks very close to what I need but does not yet give me the result I need.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors