Dynamic Column Name change Based on Slicer Selection - powerbi

Any one could you please help me on Dynamic Column Name change Based on Slicer Selection.
below is the senario.
Matrix visual
product Name Year
XXX 56
YYY 87
ZZZ 78
Slicer Selection
Year
2016-17
2017-18
2018-19
2019-20
when i select year 2017-18 , column name on matrix should change dynamicaaly as Year 2017-18 .

Related

Radar Chart Comparison - Aggregate Data - 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.

Power BI - Selecting and Filtering Columns based on Slicer Selection

Hello Stack Overflow Community,
In the attached excel sheet image, there are 5 columns (cols B to F) that have arbitrary sales numbers for years 2016-2020. In the report there will be a year slicer of each of these years. I want to calculate the total sales depending on the selection in the year slicer. However, there are 15 columns towards the end which dictate whether a particular company should be included in the total sales calculation. Only if the column corresponding to the selection by the user is N, the value should be included in the total sales calculation.
Example: If the user selects 2016,2017 and 2018 in the year slicer, Power BI should look into the column Excluded 2016-2017-2018 and include/ exclude the sales numbers of the respective years and finally return a table as below
Year Sales (Total)
2016 393
2017 561
2018 580
There is two problem in your case : the first is to be able to calcule with the filter and I think it will be easier if you do this in Excel and the second problem is to use a filter on a combinaison of imput to select only one value.
For the fist problem you could probably do something like that :
=IF(H2="Y";F2;0) / =IF(I2="Y";G2;0) / =IF(J2="Y";G2+F2;0)
and use the power of excel to slide the formula to the bottom of your table
And the next step is to sum the entire column and pivot the table :
But for the selection of the right row with your slicer on date i can't find a solution maybe you need to build a slider for all combinaison : 2016 / 2017 and 2016-2017,...

Check if value is in another table and add columns in Power BI

I have 2 tables, table1 contains some survey data and table2 is a full list of students involved. I want to check if Name in table2 is also found in table1. If yes, add Age and Level information in table2, otherwise, fill these columns with no data.
table1:
id Name Age Level
32 Anne 13 Secondary school
35 Jimmy 5 Primary school
38 Becky 10 Primary school
40 Anne 13 Secondary school
table2:
id Name
1 Anne
2 Jimmy
3 Becky
4 Jack
Expected output:
id Name Age Level
1 Anne 13 Secondary school
2 Jimmy 5 Primary school
3 Becky 10 Primary school
4 Jack no data no data
Update:
I created a relationship between table1 and table2 using the common column id(which can be repeated in table1).
Then I used:
Column = RELATED(table1[AGE])
but it caught error:
The column 'table1[AGE]' either doesn't exist or doesn't have a relationship to any table available in the current context.
There are various ways to achieve the desired output, but the simplest of them I found is to use the RELATED DAX function. If you found this answer then mark it as the answer.
Create a relationship between table1 and table2 using 'Name` column.
Create a calculated column in table2 as:
Column = RELATED(table1[AGE])
Repeat the same step for the Level column also.
Column 2 = RELATED(table1[LEVEL])
This will give you a table with ID, Name, Age, and Level for the common names between the two tables.
Now to fill those empty rows as no data, simply create another calculated column with following DAX:
Column 3 = IF(ISBLANK(table2[Column]), "no data", table2[Column])
Column 4 = IF(ISBLANK(table2[Column 2]), "no data", table2[Column 2])
This will give you the desired output.
EDIT:- You can also use the following formula to do the same thing in a single column
Column =
VAR X = RELATED(table`[AGE])
VAR RES = IF(ISBLANK(X), "no data", X)
RETURN
RES
and
Column 2 =
VAR X = RELATED(table1[LEVEL])
VAR RES = IF(ISBLANK(X), "no data", X)
RETURN
RES
This will also give you the same output.

Power BI - Create a column to show the data against one item

I have a table with repeating values in a single column, I am trying to filter the data corresponding to just one value. I have tried Pivoting the table and it didn't help, it would be helpful to get the solution using DAX or Power Query.
S.No.
Make
Sale Date
1
Mercedes
01.08.2020
2
BMW
02.08.2020
3
Hyundai
03.09.2020
4
Honda
04.06.2020
5
BMW
16.03.2020
6
BMW
06.08.2020
7
Mercedes
01.02.2021
8
Honda
18.08.2020
9
BMW
12.04.2020
10
Honda
10.03.2021
I need each Make to display their own Sale Date's in their own column similar to the table below
BMW
02.08.2020
16.03.2020
06.08.2020
12.04.2020
Using your example data:
In the data editor, select the Make and Sale Date and Pivot the items
Ensure that the 'Values Column' is 'Sale Date' and that the aggregate value is set to 'Don't Aggregate'
Which will give you a table with each make in its own column, and the dates of the sale

How to multiple two columns in a row with max date in PowerBi?

This is my first PowerBi report. 
I've a table structure like this
TransDate UnitsAsOf Price InvestedAmount Stock
01/02/2020 10 12.4 124 APL
01/03/2020 20 13 260 APL
01/05/2020 21 15 315 APL
01/10/2020 1 111 111 BPL
And this is the table Visualization I'm creating
Stock Total invested (Summarized column) Current Value
APL 699 THIS IS A MEASURE column
BPL 111
I just couldn't figure out how to get max(transDate) for each stock and multiple it with the Price of that row?
Any help please?
You can do it like this
measure =
SUMX(TOPN(1, YourTable, YourTable[TransDate], DESC), YourTable[Price] * YourTable[InvestedAmount])
the TOPN will return you the row with the latest date, and in the SUMX you use the fields from that row.
OPTION-1
You can simply create this following measure-
max_date = MAX(your_table_name[TransDate])
Now add a table visual with column - Stock, InvestedAmount (Default SUM applied) and New Measure max_date. The output will be as below-
OPTION-2
You can also add all 3 column - Stock, InvestedAmount and TransDate directly and select Latest for TransDate as shown below and the output will be same-