The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Bonjour à tous,
Je cherche à faire une mesure simple mais je ne trouve pas la solution.
Mon modèle est composé d'une table avec 4 colonnes : ID;Date_Début;Date_Fin;Prix_journalier et d'une table DATE.
L'objectif est d'obtenir année par année la somme des Prix_Journalier pour la période écoulé.
Par exemple, le produit 1 à une Date_Début = 18/12/2020 et Date_FIN = 05/01/2021 et un prix journalier = 1, j'aimerais retourner un tableau avec pour valeur en 2020 : 13 et pour 2021 : 5
J'ai crée une mesure =
Solved! Go to Solution.
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
User | Count |
---|---|
26 | |
10 | |
8 | |
6 | |
6 |
User | Count |
---|---|
31 | |
11 | |
10 | |
10 | |
9 |