Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi,
Im working to create a calculated column with the average sales of last 12 months.
But I don't know how to filter the last 12 months, I've tried in many ways but Powerbi alwys returns error. Can someone help me on this.
Solved! Go to Solution.
Hi @crhisbergas ,
Tweak the formula like this:
Sales_12Mth =
VAR __Today =
TODAY ()
VAR __12MonthsAgo =
EOMONTH ( __Today, -12 )
VAR __Begin =
DATE ( YEAR ( __12MonthsAgo ), MONTH ( __12MonthsAgo ), DAY ( __Today ) )
RETURN
SUMX (
FILTER (
Sales,
Sales[Cod_Cliente] = Clients[ID_Cliente]
&& Sales[Cod_Prod] = Sales_Clients[ID_Produto]
&& Sales[Date] >= __Begin
&& Sales[Date] <= __Today
),
Sales[Quantidade]
)
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @crhisbergas ,
Is your problem solved? If so, would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirment will find the solution quickly and benefit here, thank you!
Best Regards,
Community Support Team _ kalyj
Hi @crhisbergas ,
Is your problem solved? If so, would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirment will find the solution quickly and benefit here, thank you!
Best Regards,
Community Support Team _ kalyj
Hi All,
with your support I can finish the job.
thanks a lot!!!
@crhisbergas Try:
Sales_12Mth =
VAR __Today = TODAY()
VAR __12MonthsAgo = EOMONTH(__Today, -12)
VAR __Begin = DATE(YEAR(__12MonthsAgo), MONTH(__12MonthsAgo), DAY(__Today))
VAR __Result =
SUMX(
FILTER(
Sales,
Sales[Cod_Cliente] = Clients[ID_Cliente] &&
Sales[Cod_Prod] = Sales_Clients[ID_Produto]) &&
Sales[Date] >= __Begin && Sales[Date] <= __Today,
Sales[Quantidade]
)
Hi Greg,
When I tried to run its showing the message.
The syntax )' it's incorrect. --- Error message:
A sintaxe de ')' está incorreta. (DAX( VAR __Today = TODAY() VAR __12MonthsAgo = EOMONTH(__Today, -12) VAR __Begin = DATE(YEAR(__12MonthsAgo), MONTH(__12MonthsAgo), DAY(__Today)) VAR __Result = SUMX( FILTER( Sales, Sales[Cod_Cliente] = Clients[ID_Cliente] && Sales[Cod_Prod] = Sales_Clients[ID_Produto] && (Sales[Date] >= __Begin && Sales[Date] <= __Today), Sales[Quantidade])))).
Hi @crhisbergas ,
Tweak the formula like this:
Sales_12Mth =
VAR __Today =
TODAY ()
VAR __12MonthsAgo =
EOMONTH ( __Today, -12 )
VAR __Begin =
DATE ( YEAR ( __12MonthsAgo ), MONTH ( __12MonthsAgo ), DAY ( __Today ) )
RETURN
SUMX (
FILTER (
Sales,
Sales[Cod_Cliente] = Clients[ID_Cliente]
&& Sales[Cod_Prod] = Sales_Clients[ID_Produto]
&& Sales[Date] >= __Begin
&& Sales[Date] <= __Today
),
Sales[Quantidade]
)
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
27 | |
26 | |
23 | |
12 | |
10 |
User | Count |
---|---|
25 | |
21 | |
19 | |
19 | |
11 |