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
depple
Helper III
Helper III

Last sale, qty and non-sales

Hi,

 

I am working on a report that is supposed to show when our customers bought our products the last time and at which qty.

 

My table structure is as follows:

 

PRODUCT TABLE

Product
PA
PB
PC

 

CUSTOMER TABLE

Customer
C1
C2
C3

 

SALES TABLE

DateProductQtyCustomer
01.04.2020PA1C1
02.04.2020PA4C2
03.04.2020PB5C2
04.04.2020PC8C3
05.04.2020PA8C1

 

MATRIX VISUAL (desired outcome)

CustomerProductLast DateLast Qty
C1PA05.04.20208
C1PB  
C1PC  
C2PA02.04.20204
C2PB03.04.20205
C2PC  
C3PA  
C3PB  
C3PC04.04.20208

 

It is also key that non-sales also show.

 

As I am not particularly proficient in writing DAX, I would deeply appreciate if I could get help with the formulas here.

 

Regards,

depple

2 ACCEPTED SOLUTIONS
Sujit_Thakur
Solution Sage
Solution Sage

Dear friend , 

You can try 

 

Last_Date = MAXX(Sales table , Date )

 

If any doubt please let ke know 

Appreciate by giving kudos and selecting this post as solution if it solved your problem

 

 

Regards

Sujit

View solution in original post

v-xicai
Community Support
Community Support

Hi @depple ,

 

Assuming there are already relationships between table Sales and other two tables on field [Product] and [Customer] with Both of Cross filter direction, then you may create measures like DAX below.

 

Last Date =
CALCULATE (
    MAX ( 'SALES'[Date] ),
    ALLEXCEPT ( 'SALES', 'SALES'[Customer], 'SALES'[Product] )
)


Last Qty =
CALCULATE (
    MAX ( 'SALES'[Date] ),
    FILTER (
        ALLEXCEPT ( 'SALES', 'SALES'[Customer], 'SALES'[Product] ),
        'SALES'[Date] = 'SALES'[Last Date]
    )
)

 

Then you may put 'PRODUCT'[Product] , 'CUSTOMER'[Customer] and two created measures into table visual, turn of the option "Show items with no data" for the 'PRODUCT'[Product] and  'CUSTOMER'[Customer] in Field tab.

 

For example:

Show items with data.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-xicai
Community Support
Community Support

Hi @depple ,

 

Assuming there are already relationships between table Sales and other two tables on field [Product] and [Customer] with Both of Cross filter direction, then you may create measures like DAX below.

 

Last Date =
CALCULATE (
    MAX ( 'SALES'[Date] ),
    ALLEXCEPT ( 'SALES', 'SALES'[Customer], 'SALES'[Product] )
)


Last Qty =
CALCULATE (
    MAX ( 'SALES'[Date] ),
    FILTER (
        ALLEXCEPT ( 'SALES', 'SALES'[Customer], 'SALES'[Product] ),
        'SALES'[Date] = 'SALES'[Last Date]
    )
)

 

Then you may put 'PRODUCT'[Product] , 'CUSTOMER'[Customer] and two created measures into table visual, turn of the option "Show items with no data" for the 'PRODUCT'[Product] and  'CUSTOMER'[Customer] in Field tab.

 

For example:

Show items with data.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-xicai ,

 

Thank you for your suggestion!

 

Sorry for taking so long coming back to you, but I have had major issus with the relationships in my model with the "Both" filter direction. It turned out impossible to have 2 x "Both", because a required data table is linked to both Customer and Product. With inspiration from your suggestions, I have now nearly worked my way around the issue.

 

I really appreciate your efforts in trying to help me.

 

Regards,

depple

amitchandak
Super User
Super User

@depple , Join both table sales Create

Max(Date)

And display it with show item with no data option for both dimension table

ShowItemwithoutdata.JPG

@amitchandak

 

Thank you for trying to help me.

 

I do not understand what you mean by "Join both table sales". Could you please elaborate a little on that?

 

Regards,

depple

Sujit_Thakur
Solution Sage
Solution Sage

Dear friend , 

You can try 

 

Last_Date = MAXX(Sales table , Date )

 

If any doubt please let ke know 

Appreciate by giving kudos and selecting this post as solution if it solved your problem

 

 

Regards

Sujit

Hi @Sujit_Thakur,

 

Thank you for your suggestion, it appears to work perfectly!

 

Do you know how I could get the corresponding "Last_Qty" for "Last_Date"? 

 

Regards

depple 

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.