Radar Chart Comparison - Aggregate Data - PowerBI - powerbi

I am trying to create a radar chart which allows me to aggregate data and allow me to control the aggregations with slicers. I have the following table with data ready prepared in Power Query with all the unpivoting done. The following table is called Sheet1.
ID
Continent
Country
City
Year
Attribute
Value
1
Europe
Germany
Berlin
2021
F1
50
1
Europe
Germany
Berlin
2021
F2
60
1
Europe
Germany
Berlin
2021
F3
76
1
Europe
Germany
Berlin
2021
F4
80
1
Europe
Germany
Berlin
2021
F5
30
2
Africa
Nigeria
Lagos
2022
F1
23
2
Africa
Nigeria
Lagos
2022
F2
11
2
Africa
Nigeria
Lagos
2022
F3
23
2
Africa
Nigeria
Lagos
2022
F4
23
2
Africa
Nigeria
Lagos
2022
F5
30
2
Africa
Nigeria
Lagos
2022
F6
64
3
Asia
Japan
Tokyo
2021
F1
34
3
Asia
Japan
Tokyo
2021
F3
32
4
Asia
Japan
Tokyo
2021
F1
45
Averaging everything for the year is easy, with an extra table named Year, with one column also named Year and 2 rows, 2021 and 2022. This column goes into a slicer.
Year
2021
2022
The category will be Sheet1[Attribute] and the following measure going to the Y Axis:
_value-slicer_Avg = SWITCH(SELECTEDVALUE('Year'[Year]),
2021,
CALCULATE(AVERAGE(Sheet1[Value]),Sheet1[Year]=2021),
2022,
CALCULATE(AVERAGE(Sheet1[Value]),Sheet1[Year]=2022)
)
This yields the average for a year of choice, when I drop the Year column of the Year table into the slicer
Average
What I want to be able to, is to add another dataset on top of it, which would be easy in case of the data of an ID only (see the Individual Comparison tab of the attached pbix)
Duplicating the table in PowerQuery (no relations needed) as below...
Tables
...I need to create these measures:
_slicer_individual_selection =
SELECTEDVALUE(Sheet1_New[ID])
_value-slicer_individual_selection =
CALCULATE(AVERAGE(Sheet1[Value]),FILTER(Sheet1, Sheet1[ID] = [_slicer_individual_selection]))
And drop the ID of the Sheet1_New table in another slicer.
Individual Comparison
What I want however, is for the second dataset to be the set of the averages of the IDs selected, and the selection should be available at Continent, Country, City or ID level (see the Aggregate Comparison tab of the pbix file attached).
My attempt is not correct, but for the sake of illustration, here it is:
I have replaced the following measure in the Y Axis of the radar chart:
_value-slicer_individual_selection
with this one
_value-slicer_multiple_selection =
CALCULATE(AVERAGE(Sheet1[Value]),FILTER(Sheet1, Sheet1[ID] IN ALLSELECTED(Sheet1_New[ID])))
Failed Attempt of Aggregate Comparison
It also doesn't let me see all the continents, countries, cities or IDs available, I have to keep selecting things to make them show up. I want to be able to show the aggregate set of any selection of IDs based on the supersets available (continent, country, city) as the second set on top of the original aggregate per year. In the above example, I want to see the average for all the data from Tokyo (please note: for 2021 only) as the second set.
Also, I want the 4 slicers on the right-hand side to update, so that I only get to select the ones for 2021 when the selected Year is 2021 and the same for 2022.
Attachments are not supported, please download them from here: https://drive.google.com/drive/folders/1aHS0kFCIUe407bS59VF_MUhrLygc5wfh

To solve your case I'd do following:
Remove YEAR table and substitute values in the slicer With Sheet1[Year]. All other slicer make of Sheet1 columns.
Substitute Sheet1_New with Attributes. Link Attributes[Attribute] to Sheet1[Attribute]. Use Attributes[Attribute] for category in the chart. If you don't want the link then use TREATAS(), but it will slower the measure. The reason for Attributes[Attribute] is that if you use Sheet1[Attribute] as category in the chart, you may filter Attribute values and it will distroy the chart.
Change your _value-slicer_Avg to:
_value-slicer_Avg =
CALCULATE(
AVERAGE(Sheet1[Value])
,ALLEXCEPT(Sheet1,Sheet1[Attribute],Sheet1[Year])
)
All your Other measures do like this:
_value-slicer_individual_selection =
CALCULATE(
AVERAGE(Sheet1[Value])
,ALLEXCEPT(
Sheet1
,Sheet1[Year]
,Sheet1[Attribute]
,Sheet1[ID]
)
)
Make your slicers not influencing Sheet1[Year] slicer and each other except chart. Sheet1[Year] should filter all visuals. Chart should not infuence any sclicer. look at pictures
You can create table with unique values of Attibutes as follows:
Attributes = VALUES(Sheet1[Attribute])
I didn't link it with a Sheet1, so TREATAS was added.
Below the measure which works with multiple selection.
_Avg =
CALCULATE(
AVERAGE(Sheet1[Value])
,TREATAS(Attributes,Sheet1[Attribute])
)
This measure will show average in respect of year only
_value-slicer_Avg =
CALCULATE(
AVERAGE(Sheet1[Value])
,ALLEXCEPT(Sheet1,Sheet1[Year])
,TREATAS(Attributes,Sheet1[Attribute])
)
Regarding slicer look at the picture below:
Try to adjust filtering of slicers and the chart as you need.

Related

PowerBI Previous Month Running Total for Filtered Categories

The questions relates to DAX/PowerBI.
I've been trying to calculate a total for previous month for columns that contain only specific criteria (project name). My table looks more or less like this and is named Project Costs:
Project Name
Date
Cost in Month
Month
Year
X
01/01/2021
2.000,00
1
2021
Y
01/01/2021
1.500,00
1
2021
Z
01/01/2021
4.800,00
1
2021
X
01/02/2021
3.000,00
2
2021
Y
01/02/2021
3.500,00
2
2021
Z
01/02/2021
2.200,00
2
2021
X
01/03/2021
1.000,00
3
2021
Y
01/03/2021
6.000,00
3
2021
Z
01/03/2021
2.000,00
3
2021
I have a slicer in my report that allows me to select from all my projects.
I want to be able to visualize different financial data relating only to the project currently selected with the slicer. I managed set up calculations for cost to date, labour to date etc., however, I am struggling to find a way to calculate a rolling previous month cost relating only to the selected project, that would be susceptible to the slicer in the visuals.
I've tried the following:
Prev Month Cost Rolling =
SUMX(RELATEDTABLE('Project Costs'), 'Project Costs'[Cost in Month],
DATEADD('Project Costs'[Date], -1, MONTH))
And it does not work as it says the max. argument count for SUMX is 2.
I have tried solutions suggested here too, but they don't work either (I might be doing th wrong): Power BI Rolling Total Previous Month DAX
Expected result:
Once the report is filtered to a project Z, in March I would expect to see in card visuals:
Cost to date: 9.000,00
Cost in previous month: 2,200.
When filtered for X in March it would want it to be as follows:
Cost to date: 6.000,00
Cost in previous month: 3.000,00
I want to calculate the entire previous month, not month to date.
I would appreciate any advise on how to tackle it!
Thanks,
J
Have a look at these measures:
Total Project Cost = CALCULATE([Cost], FILTER(ALL(Projects[Date]), Projects[Date] <= MAX(Projects[Date]))) - this shows all historical costs up to the selected date.
Cost = SUM(Projects[Cost in Month]) - can be used for costs in current month, for instance
Cost previous month = CALCULATE([Cost], PREVIOUSMONTH('Projects'[Date]))

How to remove or exclude rows from a table using date slicer selection?

As per the below scenario,I need to exclude all the rows in the table Sales with columns Client,sales,salesdate and region which fall outside the selected maximum and minimum date range of the date slider.
Could anyone please suggest a DAX , I will share my DAX query which is not working.I tried to search official guides in PowerBI for selectedValues() to handle this date filter condition but nothing seems to be working.
I created a Calendar table with distinct values of the dates as present in the Sales Dates column of the Sales table. There is no relationship between these two tables. I used the below DAX measures to handle the filtering criteria for excluding the rows:-
Below measures are meant to find maximum and minimum dates in the selection slider
MaxDate=MAX(DateDimention[Dates])
MinDate=MIN(DateDimention[Dates])
Below ExcludedMeasure is meant to set 1 flag to the values other than selected values which are selected for both min and max dates.
I dragged and dropped it in the visual filter of my table Sales and set it to dont show.But it seems to be not working.
Please suggest how can I fix it.
ExcludeMeasure = IF (SELECTEDVALUE(Calendar,Calendar[MinDate],0,1),
IF (SELECTEDVALUE(Calendar,Calendar[MaxDate],0,1)
My Present Visualization and independent Calendar table to be used in the filter slider:-
Present visualization
Independent Calendar Table
Input data source [Excel]
Client Sales SalesDates Region
A 1000 1.1.2000 USA
A 100 1.2.2000 USA
A 200 4.3.2000 USA
B 110 4.3.2000 Europe
B 1000 5.4.2000 Europe
B 200 6.8.2001 Europe
C 1100 7.9.2001 Asia
C 2000 8.12.2001 Asia
D 100 1.2.2002 Australia
D 1300 6.3.2002 Australia
E 100 7.5.2002 Africa
Expected Results :
If I select Minimum slider date as 01.04.2001 and maximum slider date as 1.09.2001 in my[Dates] filter visualization, then it should return the below results after excluding '5.4.2001' and '6.8.2001':-
Client Sales SalesDates Region
A 1000 1.1.2000 USA
A 100 1.2.2000 USA
A 200 4.3.2000 USA
B 110 4.3.2000 Europe
C 1100 7.9.2001 Asia
C 2000 8.12.2001 Asia
D 100 1.2.2002 Australia
D 1300 6.3.2002 Australia
E 100 7.5.2002 Africa
Kind regards
Sameer
A relationship between the date table and the sales table would be ideal, as when you filter the date from the date table, the filter would exclude the records from the sale tables.
If you can't have a date table with the relationship, your exclude measure needs to be something like this:
Exclude =
CALCULATE(COUNT(Sales[Id]),
Sales[SalesDates] >= [MinDate] &&
Sales[SalesDate] <= [MaxDate]) > 0

Filter table based on a specific date plus 7 days

I have a table containing a date field (from 1 March 2020 to now) that I need to filter to a specific date and the previous 6 days to give complete week's data. So if I chose 30 March I'd get a table of 24 March to 30 March. If I then chose 31 March the table would show 25 March to 31 March.
I can use a date slicer to choose a range of dates but I want to be able to pick a single date, with Power BI automatically selecting the earlier date.
Any pointers much appreciated.
Mark.
You can create two measure - one for Slicer selected date and Another one with 7 day minus from the selected date as below-
Considering your date table name is- Dates
selected_date = SELECTEDVALUE(Dates[Date])
seven_day_starts_from = DATEADD(Dates[Date],-7,DAY)
Now create your calculated measure first like-
total_sales = SUM(Sales[sale])
Here comes how you will always calculate last 7 days sales considering the selected date in the slicer-
7_day_sales =
(
CALCULATE(
[total_sales],
DATESBETWEEN(
'Dates'[Date],
[seven_day_starts_from],
[selected_date]
)
) + 0
)
Remember, this is just a sample flow showing how it should work. You should try to follow the steps with your data and table structure. Dates table is a calendar table and Sales table is connected to the Dates table using the Date column.

How do I filter the columns of a table visualization?

Using the following sales table as an example which records the volume of products sold by each salesperson per year:
I created a stacked column visualization showing products sold per year:
What I want to happen when I click on "Cakes" is a report to show:
Resource, Year, Cakes
Rajeev Argwal, 2018, 678
Rajeev Argwal, 2019, 876
Rajeev Argwal, 2020, 2
When I select a specific item in the stacked column such as "2019 Soup" I want the report to show:
Resource, Year, Soup
Jane Smith, 2019, 800
Rajeev Argwal, 2019, 225
What is the right approach to do this? Effectively filtering the table visualization to show only the relevant rows and columns.

Power BI : Monthly averages

I know similar questions have been asked and answered previous to this, but for the life of me, cannot get any of those working with my limited knowledge on Power BI.
I have a table which contains 8 weeks worth of data which for most parts, spans 3 months. I currently calculate the daily average which is the "total" divided by the "total in". However what I need to do, is to display the average based upon the calendar month. Therefore, September will have a difference average to that of October and that of November.
Here's a sample of the data:
Date,Total In,Total Out,Daily Average,Total,Month
27 September 2017,10773,264,97.61,11037,September
28 September 2017,11198,382,96.70,11580,September
29 September 2017,17753,1122,94.06,18875,September
30 September 2017,9568,649,93.65,10217,September
28 October 2017,11434,938,92.42,12372,October
29 October 2017,1541,60,96.25,1601,October
30 October 2017,918,4,99.57,922,October
31 October 2017,8565,24,99.72,8589,October
01 November 2017,11452,635,94.75,12087,November
02 November 2017,7785,531,93.61,8316,November
So for November I would like to have the figure as (11452 + 7785) / (12087 + 8316) * 100 = 94.29%. Obviously, that figure would be present for all dates in November as an extra column. For October it would be (11434 + 1541 + 918 + 8565) / (12372 + 1601 + 922 + 8589) * 100 = 95.63%. I would then use the extra column and plot it on a line/bar chart.
So the above data would become:
Date,Total In,Total Out,Daily Average,Total,Month,Monthly Average
27 September 2017,10773,264,97.61,11037,September,96.00
28 September 2017,11198,382,96.70,11580,September,96.00
29 September 2017,17753,1122,94.06,18875,September,96.00
30 September 2017,9568,649,93.65,10217,September,96.00
28 October 2017,11434,938,92.42,12372,October,95.63
29 October 2017,1541,60,96.25,1601,October,95.63
30 October 2017,918,4,99.57,922,October,95.63
31 October 2017,8565,24,99.72,8589,October,95.63
01 November 2017,11452,635,94.75,12087,November,94.29
02 November 2017,7785,531,93.61,8316,November,94.29
I am having trouble getting my head around the SUMMARIZE functions etc in order to get this working without any help. So any help and explanation would be greatly appreciated.
Thanks.
Create a DAX using the EARLIER function should do the trick:
Month Average =
VAR sum_total_in =
CALCULATE(
SUM('table'[Total In]),
FILTER(
'table',
'table'[Month] = EARLIER('table'[Month])
)
)
VAR sum_total =
CALCULATE(
SUM('table'[Total]),
FILTER(
'table',
'table'[Month] = EARLIER('table'[Month])
)
)
RETURN sum_total_in / sum_total
So basically it sums the Total In and Total within the same month and returns the division.
Results:
P.S. You'll need to add the year to the filter as well if you have data across years with the same month.
I see you're asking your question from a DAX perspective, but here's a Power Query based answer that's quite easy. Starting with your table in Power Query (Power BI's Query Editor):
Select the Month column, then Transform -> Group By, and set up the dialog box like this...
and click OK.
You'll see this:
Then click the button at the top of the
AllData column to expand the nested tables, and set up the dialog box like this...
and click OK.
You'll see this:
Now click Add Column -> Custom Column, and set up the dialog box like this...
and click OK.
You'll see this:
Now select the first three columns (Month, Sum Total In, Sum Total) and click Home -> Remove Columns.
You'll see this:
You can double-click the Month.1 column title and rename it if you like.