Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi guys
I need to create one single graph with the following things:
evolution on months on
sales actual for multiple categories of products
sales target for multiple categories of products
sales actual for the year before for multiple categories of products
something like:
in jan 2023 we sold 30 hats and the target was 40 for this product, and the year before in te same month we sold 50
I've created a measure using same period last year to get the numbers for sales actual per each product category
Any idea how I can create such a graph, I need only one for everything above
Pls bare in mind that I am no great expert in PBI
Thanks so much!
Solved! Go to Solution.
Please try this:
First pf all, I create a set of sample data:
Then add a new table:
Table 2 = {"now","Last year"}
Two measures created:
actualSales =
VAR _newtable =
SELECTEDVALUE ( 'Table 2'[Value] )
VAR _currentDate =
MAX ( 'Table'[date] )
VAR _currentProduct =
SELECTEDVALUE ( 'Table'[Products] )
RETURN
SWITCH (
_newtable,
"now",
CALCULATE (
SUM ( 'Table'[actual] ),
FILTER (
ALLSELECTED ( 'Table' ),
YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
),
"Last year",
CALCULATE (
SUM ( 'Table'[actual] ),
FILTER (
ALL ( 'Table' ),
YEAR ( 'Table'[date] )
= YEAR ( _currentDate ) - 1
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
)
)
targetSales =
VAR _newtable =
SELECTEDVALUE ( 'Table 2'[Value] )
VAR _currentDate =
MAX ( 'Table'[date] )
VAR _currentProduct =
SELECTEDVALUE ( 'Table'[Products] )
RETURN
SWITCH (
_newtable,
"now",
CALCULATE (
SUM ( 'Table'[Target] ),
FILTER (
ALLSELECTED ( 'Table' ),
YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
),
"Last year",
CALCULATE (
SUM ( 'Table'[Target] ),
FILTER (
ALL ( 'Table' ),
YEAR ( 'Table'[date] )
= YEAR ( _currentDate ) - 1
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
)
)
Then add two slicer with the filed of the products and date separately:
A line and clustered column chart can be created:
The result is as follow:
If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Please try this:
First pf all, I create a set of sample data:
Then add a new table:
Table 2 = {"now","Last year"}
Two measures created:
actualSales =
VAR _newtable =
SELECTEDVALUE ( 'Table 2'[Value] )
VAR _currentDate =
MAX ( 'Table'[date] )
VAR _currentProduct =
SELECTEDVALUE ( 'Table'[Products] )
RETURN
SWITCH (
_newtable,
"now",
CALCULATE (
SUM ( 'Table'[actual] ),
FILTER (
ALLSELECTED ( 'Table' ),
YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
),
"Last year",
CALCULATE (
SUM ( 'Table'[actual] ),
FILTER (
ALL ( 'Table' ),
YEAR ( 'Table'[date] )
= YEAR ( _currentDate ) - 1
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
)
)
targetSales =
VAR _newtable =
SELECTEDVALUE ( 'Table 2'[Value] )
VAR _currentDate =
MAX ( 'Table'[date] )
VAR _currentProduct =
SELECTEDVALUE ( 'Table'[Products] )
RETURN
SWITCH (
_newtable,
"now",
CALCULATE (
SUM ( 'Table'[Target] ),
FILTER (
ALLSELECTED ( 'Table' ),
YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
),
"Last year",
CALCULATE (
SUM ( 'Table'[Target] ),
FILTER (
ALL ( 'Table' ),
YEAR ( 'Table'[date] )
= YEAR ( _currentDate ) - 1
&& MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
&& 'Table'[Products] = _currentProduct
)
)
)
Then add two slicer with the filed of the products and date separately:
A line and clustered column chart can be created:
The result is as follow:
If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Wow.. this is amazing! Thank you so much for your time on this! You're amazing!!!
User | Count |
---|---|
123 | |
77 | |
62 | |
50 | |
49 |
User | Count |
---|---|
175 | |
125 | |
60 | |
60 | |
58 |