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
kta87
Helper I
Helper I

Measure Net Sales calculated before and after a specific date from other table

Dear pro's,

 

I have to build two measures which are giving me a hard time. Both are almost identical, the only difference is the filtering, one is before and the second after or equal a specific date from other table. 

So the first table (SALES) that I've got is containing the net sales by customer ID, product ID, calendar day and net sales.

 

Customer IDProduct ID

Calendar Date

Net Sales
88331458

07/12/2023

 

0.2
8837320516/11/20230.4
8837320509/11/20230.4
8837320523/11/20230.6
8833194707/12/20230.6
8826794616/11/20230.01
8830264709/11/20230.2
8830264707/12/20230.2
16930264709/11/20230.2
16924215202/11/20230.2
35426615023/11/20230.2
35424215207/12/20230.4
35433194707/12/20230.6
35437320516/11/20230.8
35437320523/11/20231.2

 

 

The second table (EVENTS) is containing the events details.

 

Customer IDEvent IDEvent Date
88Event110/11/2023
88Event216/11/2023
169Event105/11/2023
354Event112/11/2023
354Event216/11/2023
354Event323/11/2023

Both tables are linked to a Calendar Table (CALENDAR) and a Customer Table (CUSTOMER).

What I want to achieve is a table where I want to see the net sales before the event date and the net sales after or equal the event date.

 

Customer IDEvent IDEvent DateNet Sales BeforeNet Sales After
88Event110/11/20230.82.01
88Event216/11/20230.82.01
169Event105/11/20230.20.4
354Event112/11/202303.2
354Event216/11/202303.2
354Event323/11/20230.82.4


I've tried the following formula, but is not returning the correct values.

 

Before Event =
CALCULATE ([Net Sales],FILTER(SALES,SALES[Calendar Date]<MAX(EVENTS[Event Date])


Thank you in advance
1 ACCEPTED SOLUTION

Hi @v-yifanw-msft ,

 

Thank you for the response. Unfortunately those measures are returning blank also.
Luckly I've managed to figure it out by my self. The correct measure was the first one posted by me in the initial request and all I had to do was to add a slicer (Single Select) for the EVENT ID.

 

 

View solution in original post

4 REPLIES 4
v-yifanw-msft
Community Support
Community Support

Hello @kta87 ,

 

Thank you for your question. You can follow these steps:

 

  1. Create a measure

 

 Net Sales Before = 
CALCULATE (
    SUM ( SALES[Net Sales] ),
    FILTER (
        ALL ( SALES ),
        'SALES'[Customer ID] = SELECTEDVALUE ( 'Table'[Customer ID] )
            && 'SALES'[Calendar Date] < SELECTEDVALUE ( 'Table'[Event Date] )
    )
)
  1. Create another measure

 

    Net Sales After = 
CALCULATE (
    SUM ( SALES[Net Sales] ),
    FILTER (
        ALL ( SALES ),
        'SALES'[Customer ID] = SELECTEDVALUE ( 'Table'[Customer ID] )
            && 'SALES'[Calendar Date] >= SELECTEDVALUE ( 'Table'[Event Date] )
    )
)

vyifanwmsft_1-1702542599566.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Yifan Wang

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

 

Hi @v-yifanw-msft ,

 

Thank you for the response. Unfortunately those measures are returning blank also.
Luckly I've managed to figure it out by my self. The correct measure was the first one posted by me in the initial request and all I had to do was to add a slicer (Single Select) for the EVENT ID.

 

 
smpa01
Super User
Super User

@kta87  can you try this

before = CALCULATE(SUM(Sales[Net Sales]), FILTER(All(Sales),Sales[Customer ID]=MAX(Event[Customer ID])&&Sales[Date]<=MAX(Event[Date])))
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

This measure is returning nothing, is blank.

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.