Forum Discussion

manojk_pbi's avatar
manojk_pbi
Helper V
2 years ago
Solved

Help need to write dax measure

Hi,

 

I have 2 tables, one with tasks details by project and another is cost% by projects. I need to create a visualization to show the Net change in the tasks Month on Month by Project and another table to show Netchange with respect to cost share (NetChange * Cost%).

 

Appreciate any suggestions or sample code for DAX

 

Data tables 

Table 1  
ProjectDateTasks
Project1Jan'24120
Project2Jan'24100
Project3Jan'24130
Project1Feb'24110
Project2Feb'2490
Project3Feb'24100
Project1Mar'2480
Project2Mar'2480
Project3Mar'24145
Project1Apr'2495
Project2Apr'2475
Project3Apr'24125
   
Table 2   
ProjectCost% 
Project126% 
Project235% 
Project339% 

 

 

required output:

Table1 for display   
ProjectJan'24Feb'24Mar'24Apr'24
Project11201108095
Project2100908075
Project3130100145125

 

Net Change : Baseline month - current month eg Jan'24-Feb'24 , Jan'24 - Mar'24, Jan'24 - Apr'24

ProjectJan'24Feb'24Mar'24Apr'24
Project1 104025
Project2 102025
Project3 30-155

 

Net Change * Cost% : for Project1 Feb'24 = 10*26%

ProjectJan'24Feb'24Mar'24Apr'24
Project1 3107
Project2 479
Project3 12-62
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  manojk_pbi ,

    Because Power BI sorts by default based on alphabetical order, we need to create a sort table

    Here are the steps you can follow:

    1. Create calculated table

    Date =
    var _date=
    CALENDAR(
        DATE(2024,1,1),
        DATE(2024,12,31))
    return
    ADDCOLUMNS(
        _date,"MonthYear",FORMAT([Date],"mmm")&"'"&FORMAT([Date],"yy"))

    Sort_Table =
    SUMMARIZE('Date','Date'[MonthYear],"mindate",MINX(FILTER(ALL('Date'),'Date'[MonthYear]=EARLIER('Date'[MonthYear])),[Date]))

    2. Select [MonthYear] – Column tools – Sort by column – [mindate].

    3. Joining two tables.

    4. Create measure.

    Baseline month - current month =
    var _today=TODAY()
    var _monthyear=MINX(FILTER(ALL('Date'),'Date'[Date]=DATE(YEAR(_today),1,1)),[MonthYear])
    var _value=SUMX(FILTER(ALL('Table'),'Table'[Project]=MAX('Table'[Project])&&'Table'[Date]=_monthyear),[Tasks])
    RETURN
    _value - MAX('Table'[Tasks])

    Net Change * Cost% =
    var _value=
    SUMX(FILTER(ALL('Table2'),
    'Table2'[Project]=MAX('Table'[Project])),[Cost%])
    return
    _value * [Baseline month - current month]

     

     

    Best Regards,

    Liu Yang

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

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  manojk_pbi ,

    Because Power BI sorts by default based on alphabetical order, we need to create a sort table

    Here are the steps you can follow:

    1. Create calculated table

    Date =
    var _date=
    CALENDAR(
        DATE(2024,1,1),
        DATE(2024,12,31))
    return
    ADDCOLUMNS(
        _date,"MonthYear",FORMAT([Date],"mmm")&"'"&FORMAT([Date],"yy"))

    Sort_Table =
    SUMMARIZE('Date','Date'[MonthYear],"mindate",MINX(FILTER(ALL('Date'),'Date'[MonthYear]=EARLIER('Date'[MonthYear])),[Date]))

    2. Select [MonthYear] – Column tools – Sort by column – [mindate].

    3. Joining two tables.

    4. Create measure.

    Baseline month - current month =
    var _today=TODAY()
    var _monthyear=MINX(FILTER(ALL('Date'),'Date'[Date]=DATE(YEAR(_today),1,1)),[MonthYear])
    var _value=SUMX(FILTER(ALL('Table'),'Table'[Project]=MAX('Table'[Project])&&'Table'[Date]=_monthyear),[Tasks])
    RETURN
    _value - MAX('Table'[Tasks])

    Net Change * Cost% =
    var _value=
    SUMX(FILTER(ALL('Table2'),
    'Table2'[Project]=MAX('Table'[Project])),[Cost%])
    return
    _value * [Baseline month - current month]

     

     

    Best Regards,

    Liu Yang

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

    • manojk_pbi's avatar
      manojk_pbi
      Helper V

      Anonymous , thanks for your quick response. I will check and try to understand your suggestion.