Forum Discussion

ParthSoni1901's avatar
ParthSoni1901
Frequent Visitor
3 years ago

Create a dynamic filter for budget selection

 

 

I have 2 filters and 1 what if parameter, I want that when I put any budget in parameter, than i can select any number of week and any number of campaigns, it will give me budget segrigation to get the highest ROI and the budget has to be devided into that week and campaigns.

I have created following dax to satisfy my problem but it is not giving me proper result it gives me either blank values or full total not the between values which I want.
 
dynamic Cost disstribution test 2 =
var Cumulative_sum = CALCULATE(
    SUM('Weekly analyzed data'[Cost]),
    FILTER(
        ALLSELECTED('Weekly analyzed data'[Analysed ROI],'Weekly analyzed data'[Week Number],'Weekly analyzed data'[Campaigns]),
        ISONORAFTER('Weekly analyzed data'[Analysed ROI], MIN('Weekly analyzed data'[Analysed ROI]), ASC)
    )
)

Var Condition_if = if(Cumulative_sum<=[Parameter Value],sum('Weekly analyzed data'[Cost]),BLANK())
Return
Condition_if


It will be really helpful if anyone can help me with this problem.

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    ParthSoni1901 OK, so you could approach this like the following. If you post the table of data as text I could test the code out. Otherwise, I'm just guessing something like this should work. Note that I have no idea how you want to return this in terms of the visual, I just used a card visual. Note that in my model, I was using Table4 as my base data table.

     

    First measure (Measure 2) guarantees the sort order such that the highest ROI is listed first.

     

    Measure 2 = 
        VAR __Budget = 20000
        VAR __Count = COUNTROWS('Table4') //Get count of rows in context
        VAR __Ordered = CONCATENATEX('Table4',[Campaigns] & "*" & [Analyzed ROI] & "*" & [Cost],"|",[Analyzed ROI],DESC) 
        //this returns a string like SEM*8.15*10000|Instagram*8.1*10000 that is ordered by ROI
        VAR __Table1 = 
            ADDCOLUMNS(
                GENERATESERIES(1,__Count,1),
                "__Row",PATHITEM(__Ordered,[Value],TEXT)
            )
        VAR __Table2 = 
            ADDCOLUMNS(
                __Table1,
                "__Campaigns",
                        VAR __RowPath = SUBSTITUTE([__Row],"*","|")
                    RETURN
                        PATHITEM(__RowPath,1,TEXT),
                "__Analyzed ROI",
                        VAR __RowPath = SUBSTITUTE([__Row],"*","|")
                    RETURN
                        PATHITEM(__RowPath,2,TEXT) + 0,
                "__Cost",
                        VAR __RowPath = SUBSTITUTE([__Row],"*","|")
                    RETURN
                        PATHITEM(__RowPath,3,TEXT) + 0
            )
        VAR __Table3 = 
            ADDCOLUMNS(
                __Table2,
                "__RT",
                        VAR __ROI = [__Analyzed ROI]
                    RETURN
                        __Budget - SUMX(FILTER(__Table2,[__Analyzed ROI] >= __ROI),[__Cost])
            )
        VAR __FinalTable = FILTER(__Table3, [__RT] >= 0)
    RETURN
        CONCATENATEX(__FinalTable,[__Campaigns] & "|" & [__Analyzed ROI] & "|" & [__Cost] & "|" & [__RT],UNICHAR(10))       

     

     

    This version does not guarantee sort order but is simpler:

     

    Measure 3 = 
        VAR __Budget = 20000
        VAR __Table = 
            ADDCOLUMNS(
                'Table4',
                "__RT",
                        VAR __ROI = [Analyzed ROI]
                    RETURN
                        __Budget - SUMX(FILTER('Table4',[Analyzed ROI] >= __ROI),[Cost])
            )
        VAR __FinalTable = FILTER(__Table, [__RT] >= 0)
    RETURN
        CONCATENATEX(__FinalTable,[Campaigns] & "|" & [Analyzed ROI] & "|" & [Cost] & "|" & [__RT],UNICHAR(10))

     

     

    The first measure converts the table to as string ordered by ROI. This is then converted back to a table by using a FOR loop (__Table1) and then parsing out the string text (__Table2). This guarantees sort order. Then, a WHILE loop (__Table3) to figure out when you have used up your budget. The (__FinalTable) "exits" the WHILE loop. 

     

    Measure 3 just uses the WHILE loop.

     

     

    • ParthSoni1901's avatar
      ParthSoni1901
      Frequent Visitor

      Sorry, But this is not what I wanted was clustred column chart where cost is distributed based on ROI and we can select based on campaigns and weeks. budget has to be distributed between the selected weeks and campaigns.

      I am attaching my Data in here.

      SEM8.1510000210000
      Instagram8.110000210000
      PPC8.0510000210000
      Youtube8.0210000210000
      Facebook810000210000
      LinkedIn7.9510000210000
      SEM7.9220000210000
      Instagram7.920000210000
      Youtube7.820000210000
      LinkedIn7.7520000210000
      PPC7.7220000210000
      Facebook7.720000210000
      Youtube7.6830000210000
      LinkedIn7.6530000210000
      SEM7.6230000210000
      Instagram7.630000210000
      SEM7.5510000110000
      Instagram7.510000110000
      PPC7.4510000110000
      SEM7.4340000210000
      Youtube7.4210000110000
      Facebook7.410000110000
      Instagram7.3940000210000
      Youtube7.3740000210000
      SEM7.3510000310000
      LinkedIn7.3440000210000
      LinkedIn7.3310000110000
      SEM7.3220000110000
      Instagram7.320000110000