Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Dynamic calculations basis Date selection

Objective:- Dynamic calculations basis Date selection

 

Requirement :- Categorise all transactions basis difference between selected date and Due Date of Transaction into different buckets as below

 

- 31-60 : if date difference between selected date and Due Date is >30, categorise it as "31-60"

- 1-30 : if date difference between selected date and Due Date is between 1-30, categorise it as "1-30"

- Current : if date difference between selected date and Due Date is <= 0, categorise it as "Current"

Create a 100% stacked bar, showing bucket-wise Net Amount

 

Scenario :- Date selected - 31/01/19

 

Refer this data

 

 

  • Hi, Anonymous 

     

    It’s my pleasure to answer for you.

    According to your description, I think you can create a calendar table to filter date, then create three similar measures,put them in 100% stacked bar chart.

    Like this:

    1-30 = 
    SUMX (
        FILTER (
            ADDCOLUMNS (
                'Table',
                "age",
                    VAR selecteddate =
                        SELECTEDVALUE ( 'Table 2'[Date] )
                    VAR duedate =
                        IF ( [Due Date] = BLANK (), TODAY (), [Due Date] )
                    RETURN
                        SWITCH (
                            TRUE (),
                            duedate - selecteddate > 30, "31-60",
                            duedate - selecteddate >= 0
                                && duedate - selecteddate < 30, "1-30",
                            duedate - selecteddate < 0, "Current",
                            BLANK ()
                        )
            ),
            [age] = "1-30"
        ),
        [Net Amount]
    )

    Here is my sample .pbix file.Hope it helps.

    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.

4 Replies

  • themistoklis's avatar
    themistoklis
    Community Champion

    Anonymous 

    In a new column add the following formula to create the groups.

    Then on the chart add the column and the net amount 

     

    Column = 
    var _selecteddate = SELECTEDVALUE('Calendar'[Date])
    return
    SWITCH (
        TRUE (),
        'Table'[Due_date] - _selecteddate > 30, "31-60",
        'Table'[Due_date] - _selecteddate >= 0 && 'Table'[Due_date] - _selecteddate < 30 , "0-30",
        'Table'[Due_date] - _selecteddate < 0, "Current",	
        BLANK()
    )
  • Anonymous , where is Due Date ?

    You can have a measure like this keep the smaller date before

     

    Days = datediff(Selectedvalue(Date[Date]), max(Table[Due Date]), day)

     

    Need a context to sum or Avg

    Sumx(values(Table[Customter]),[Days])

     

    For bucket refer my video on dynamic segmentation : https://www.youtube.com/watch?v=CuczXPj0N-k

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sorry my bad, mentioned the wrong dataset

       

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

        Hi, Anonymous 

         

        It’s my pleasure to answer for you.

        According to your description, I think you can create a calendar table to filter date, then create three similar measures,put them in 100% stacked bar chart.

        Like this:

        1-30 = 
        SUMX (
            FILTER (
                ADDCOLUMNS (
                    'Table',
                    "age",
                        VAR selecteddate =
                            SELECTEDVALUE ( 'Table 2'[Date] )
                        VAR duedate =
                            IF ( [Due Date] = BLANK (), TODAY (), [Due Date] )
                        RETURN
                            SWITCH (
                                TRUE (),
                                duedate - selecteddate > 30, "31-60",
                                duedate - selecteddate >= 0
                                    && duedate - selecteddate < 30, "1-30",
                                duedate - selecteddate < 0, "Current",
                                BLANK ()
                            )
                ),
                [age] = "1-30"
            ),
            [Net Amount]
        )

        Here is my sample .pbix file.Hope it helps.

        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.