Forum Discussion
Sumx avec des dates dynamiques
- 3 years ago
Bonjour Anonymous
First of all, excuse me, as I am replying in English after reading an English translation of your post (via Google Translate).
From what you've described, I understand that you want to sum the values of Prix_journalier, repeated for each date that is both within the currently filtered date range from the DATE table and within the range [ Date_Début, Date_FIN]
I am assuming that there is no relationship between the Produit and 'DATE' tables (but the code can be modified to work if there is a relationship).
Your idea of using SUMX over the Produit table is sensible. I would just modify it to something like below. This defines a variable DateCount which is the number of dates in the intersection of the filtered date from 'DATE' and the range defined by the current row. DateCount is then multiplied by the price for the current row:
Test Measure = SUMX ( Produit, VAR CurrentPrice = Produit[Prix_journalier] VAR CurrentDateRange = DATESBETWEEN ( 'DATE'[Date], Produit[Date_Début], Produit[Date_FIN] ) VAR DateCount = CALCULATE ( COUNTROWS ( 'DATE' ), KEEPFILTERS ( CurrentDateRange ) ) RETURN CurrentPrice * DateCount )You may want to check this for "off by one" errors, as I'm not certain whether the first/last dates should always be included.
Does this or something similar work for you?
Regards,
Owen
Bonjour Anonymous
First of all, excuse me, as I am replying in English after reading an English translation of your post (via Google Translate).
From what you've described, I understand that you want to sum the values of Prix_journalier, repeated for each date that is both within the currently filtered date range from the DATE table and within the range [ Date_Début, Date_FIN]
I am assuming that there is no relationship between the Produit and 'DATE' tables (but the code can be modified to work if there is a relationship).
Your idea of using SUMX over the Produit table is sensible. I would just modify it to something like below. This defines a variable DateCount which is the number of dates in the intersection of the filtered date from 'DATE' and the range defined by the current row. DateCount is then multiplied by the price for the current row:
Test Measure =
SUMX (
Produit,
VAR CurrentPrice =
Produit[Prix_journalier]
VAR CurrentDateRange =
DATESBETWEEN ( 'DATE'[Date], Produit[Date_Début], Produit[Date_FIN] )
VAR DateCount =
CALCULATE (
COUNTROWS ( 'DATE' ),
KEEPFILTERS ( CurrentDateRange )
)
RETURN
CurrentPrice * DateCount
)
You may want to check this for "off by one" errors, as I'm not certain whether the first/last dates should always be included.
Does this or something similar work for you?
Regards,
Owen