0
votes

I am trying to create a measure that calculates (a/qty)*100 for each month, where qty commes from Delivery table (generated with an R script)

  month        qty
  <date>     <dbl>
1 2019-02-01     1
2 2019-03-01   162
3 2019-04-01  2142
4 2019-05-01   719

And a comes from a table TABLE_A that has been created within Power BI that looks like this :

Client     Date            a
x          2019-03-07      3
x          2019-04-14      7
y          2019-03-12      2

So far, I managed to calculate that value overall with the following measure formula :

MEASURE = CALCULATE( (Sum(TABLE_A[a])/sum(Delivery[qty]))*100)

The issue I have is that I would need this measure monthly (i.e. join the tables on month) without explicitly defining a link between the tables in the PowerBI model.

1

1 Answers

1
votes

For each row in TABLE_A you need to look up the corresponding qty in Delivery, so try something along these lines:

MEASURE =
DIVIDE(
    SUM( TABLE_A[a] ),
    SUMX(
        TABLE_A,
        LOOKUPVALUE(
            Delivery[qty],
            Delivery[month], EOMONTH( TABLE_A[Date], -1 ) + 1
        )
    )
) * 100

The formula EOMONTH( TABLE_A[Date], -1 ) returns the end of the previous month relative to that date and adding 1 day to that to get the start of the current month for that date.