Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dax help

why does this not work
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous 

    Here I will explain to you based on your screenshoot and your code.

    From your screenshot we know [Margin] is a measure, you couldn't add a measure into sum. You want to get sum of [Margin] in YTD. Try sumx function. 

    [Margin] is based on [Weighted Average Yield] and [Weighted Average COF]. You need to add table name which you used in [Weighted Average Yield] and [Weighted Average COF] in Sumx.

    sumx("Data Table Name Used in two basic measures",[Margin])

     

    2. TotalYTD is a time intelligence function in Dax code, it's format is as below.

     

    Measure = TOTALYTD(<expression>,<dates>[,<filter>][,<year_end_date>])  

     

    Please make sure Detail table is a date table with continous date in it. Details[Go Live] column should be a date column.

    Make Sure the table you used to calculate [Weighted Average Yield] and [Weighted Average COF] has relationship with Detail table. 

    Totak spread YTD = TOTALYTD(SUMX('Table',[Margin]),Detail[Go Live])

     

    I build a sample, in my sample key measure table is my data table.

    Relationship:

    Measures:

    Weighted Average Yield = AVERAGE('Key Measure'[Value1])
    Weighted Average COF = AVERAGE('Key Measure'[Value2])
    Margin = [Weighted Average Yield] - [Weighted Average COF]
    Totak spread YTD = TOTALYTD(SUMX('Key Measure',[Margin]),Detail[Go Live])

     Result:

    Best Regards,
    Rico Zhou

     

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