Forum Discussion

kta87's avatar
kta87
Icon for Helper I rankHelper I
2 years ago
Solved

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
  • kta87's avatar
    kta87
    2 years ago

    Hi Anonymous ,

     

    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.

     

     

4 Replies

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    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])))
    • kta87's avatar
      kta87
      Icon for Helper I rankHelper I

      This measure is returning nothing, is blank.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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] )
        )
    )
    

    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.

     

    • kta87's avatar
      kta87
      Icon for Helper I rankHelper I

      Hi Anonymous ,

       

      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.