Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I don't know if you know that Excel can display the contained of a Data Model table. The result is quiet interesting because you can use the Custom Data Type to associate your tables directly in a worksheet.
If you don't the principe, you specify in your data model a Table with a column ID and in Excel, you can call each one of the columns of that table like in this example
As you can see, I was able to create a calculated column for the last purchase date with this measure
LastDateAchat = MAX(Ventes[Date_Commande])
And I used the previous measure for the second calculated column to return the amount of the last purchase
ValueLastPurchase = CALCULATE([CA],FILTER(Ventes,Ventes[Date_Commande]=Clients[LastDatePurchase]))
But, I'm not able to find the calculation to return the amount of sales for the previous month
SalesLast_Month =
VAR Last_Month = DATE(YEAR(TODAY()),MONTH(TODAY())-1, 1)
RETURN IF (Clients[LastDatePurchase] >= Last_Month,
CALCULATE(
[CA],
FILTER(
Ventes,
Ventes[Date_Commande]>=DATE(YEAR(Clients[LastDatePurchase]), MONTH(Clients[LastDatePurchase])-1, 1))),
BLANK())
I know that wiht a measure, it's a piece of cake but with this calculation, the result isn't the one expected
And the data model is a basic one: Clients, Products and Sales (Ventes)
Any idea to return the sales for each Client ID with a calculated column?
Thanks
Solved! Go to Solution.
Hi @selimovd ,
I have tried your solution but it doesn't solve the problem.
But I found a way to solve this with Power Query
I have created a temporary table with only the sales of the previous month and apply a group by.
And finally, I have merge the Client Table with this temparory tables.
It works, but I would prefer to do the job with a measure
Bonjour @FredLEGUEN ,
probably I found the mistake.
When you're working in a calculated column you should be aware of the context transition (when is value from the row and when from the whole table). The moment you use CALCULATE the context transition happens from the row to the filter context.
In your case this means you can't access the LastDatePurchase in the row anymore, so you have to save it before as a variable before the transition happens.
Try the following measure:
SalesLast_Month =
VAR Last_Month = DATE( YEAR( TODAY() ), MONTH( TODAY() ) - 1, 1 )
VAR vLastDatePurchase = Clients[LastDatePurchase]
RETURN
IF(
Clients[LastDatePurchase] >= Last_Month,
CALCULATE(
[CA],
FILTER(
Ventes,
Ventes[Date_Commande] >= DATE( YEAR( vLastDatePurchase ), MONTH( vLastDatePurchase ) - 1, 1 )
)
),
BLANK()
)
Hi @selimovd ,
I have tried your solution but it doesn't solve the problem.
But I found a way to solve this with Power Query
I have created a temporary table with only the sales of the previous month and apply a group by.
And finally, I have merge the Client Table with this temparory tables.
It works, but I would prefer to do the job with a measure
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
97 | |
75 | |
63 | |
53 |
User | Count |
---|---|
144 | |
103 | |
98 | |
85 | |
64 |