Forum Discussion

dirkkoch's avatar
dirkkoch
Helper III
5 years ago
Solved

Dynamic calculation along time period

Hi all,


I would need support with the following issue (see Screenshot attached). I have 2 tables (Inbound & Outbound) which are both related to a Calendar table (one to many relation). As a result I want to have a dynamic calculation for the Total stock (yellow marked column, taking into consideration the bold marked cells) always starting with today's date. Support is highly appreciated!

  • Hi, dirkkoch 

     

    You need to create three columns and a measure in calendar table. Because today is the 19th, the data has changed a bit.

    Like this:

    Column =
    VAR a =
        CALCULATE (
            COUNT ( 'Inbound table'[Stock location] ),
            FILTER ( ALL ( 'Inbound table' ), 'Inbound table'[Inbound Date] <= TODAY () ),
            'Inbound table'[Stock location] = "Location 1"
        )
    VAR b =
        SUMX (
            FILTER ( 'Calendar table', [Date ] <= EARLIER ( 'Calendar table'[Date ] ) ),
            [ColumnINBOUND]
        )
    VAR c =
        SUMX (
            FILTER ( 'Calendar table', [Date ] <= EARLIER ( 'Calendar table'[Date ] ) ),
            [ColumnOUTBOUND]
        )
    RETURN
        a + b - c
    
    Measure = IF(MAX('Calendar table'[Date ])<TODAY(),0,1)

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

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

  • Hi, dirkkoch 

     

    You can create a column.

    Like this:

    Column =
    VAR a =
        MAXX (
            FILTER (
                'Calendar table',
                [Relative Week] = EARLIER ( 'Calendar table'[Relative Week] )
            ),
            [Date ]
        )
    VAR b =
        MAXX ( FILTER ( 'Calendar table', [Date ] = a ), [Total Preview Day] )
    RETURN
        b
    

    Best Regards

    Janey Guo

     

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

  • Hi, dirkkoch 

     

    You need to create a measure,then put it to the card visual. 

    Like this:

    Measure 2 = var a=MAX('Calendar table'[Relative Week])
    return CALCULATE(MAX('Calendar table'[Column]),'Calendar table'[Relative Week]=a)

    If you can give me kudos as a reward, I will be very happy.😊

     

    Best Regards

    Janey Guo

13 Replies

  • Feedback is very welcome if anybody can offer support :-). Also if the problem needs to be specified more precisely.

    • v-janeyg-msft's avatar
      v-janeyg-msft
      Community Support

      Hi, dirkkoch 

       

      Your idea is achievable, but I don’t know how the value of 'stock level location 1' and 'sum inbound' and 'sum outbound are calculated'. Can you explain it more clearly and share some sample fake data in table? So we can help you soon.

       

      Best Regards

      Janey Guo

      • dirkkoch's avatar
        dirkkoch
        Helper III

        Hi, v-janeyg-msft 

        the values are calculated as follows (see also Screenshot with comments shared in post above):
        "stock level location 1": Calculation is starting with today's date showing total of all columns "Stock location" from "Inbound table" with value "Location 1" & date<Today (-> in examplary Screenshot "result table"=3 on 15.03.2021).

        For each following day the calculation is the "Total stock" result from yesterday (Stock level location 1 + sum Inbound - sum Outbound -> see examples from result table in Screenshot, e.g. 4 on 16.03.2021 -> 4+0-0=4)

        "Sum Inbound": Contains count of dates from "Inbound table" - column "Inbound date" where the date in "Calender table" equals "Inbound table" & is >= Today (e.g. Inbound date 13.04.2021 -> count 3)

        "Sum Outbound": Contains count of dates from "Outbound table" - column "Outbound date" where the date in "Calender table" equals "Outbound table" & is >= Today (e.g. Outbound date 10.04.2021 -> count 2)