Getting Data on Matrix Visual with dynamic column based on slicer selection - powerbi

I have a single table that combines data of all 4 versions of same Project (Project A).
excel copy
I need advise on how to add a dynamic column in Matrix Visual so that when two different versions of the Project A is selected from Slicer dropdown visual, the column dates should change according to the selection made in Slicer. For instance if "Project A - Baseline" is selected in one Slicer and "Project A - Update 01" is selected in the next slicer, the dates in matrix visual should change accordingly and DAX formula to calculate the days difference from dynamic dates column as shown in the attachment.
Matrix Visual

Simple way:
Left Project Start Date =
VAR ProjectName=MIN('Sheet1'[proj_short_name])
RETURN
CALCULATE(
SELECTEDVALUE(Sheet1[Plan_Actual_Start_Date],"more then 1 start date")
,'Sheet1'[proj_short_name]=ProjectName
)
Right Project End Date =
VAR ProjectName=MAX('Sheet1'[proj_short_name])
RETURN
CALCULATE(
SELECTEDVALUE(Sheet1[Plan_Actual_Finish_Date],"more then 1 end date")
,'Sheet1'[proj_short_name]=ProjectName
)
Matrix header= "Projects Compare " & MIN('Sheet1'[proj_short_name]) & " vs " & MAX('Sheet1'[proj_short_name])

Related

Dynamic TopN Selection problem while selecting another filter slicer?

In Power BI, I have created a dynamic TopN visual where we can see top 3 to top 10 teams in terms of total goals scored in FIFA World Cups. I am using a parameter called Top Rankings for TopN selection. However, the TopN selection does not work when I am selecting another slicer Year. When I am selecting the year slicer, the visual shows close to 10 teams although I have selected only 4 teams in the slicer parameter. I am providing the dax measure, table which is used to create the measure and the visual as well.
Dax -
# TopN Teams by Goal Scored =
VAR ranking = RANKX(ALLSELECTED(All_WC_matches[Teams]), [Overall Scored],,DESC,Dense)
Return
IF(
ranking <= 'Top Rankings'[Top Rankings Value],
[Overall Scored]
)
Only TopN slicer selected
Both TopN and Year slicers selected
Table used for the measure
This is the link to my power bi report
https://app.powerbi.com/view?r=eyJrIjoiZWRkNjRkZmQtZGM5Ny00OTQyLTlmYjgtYzNhZGUxYTFkMTQ2IiwidCI6IjllMmY0M2FmLTExYzMtNGQ5NC1iYTVlLTc3Y2QwNzJlOWMwYiJ9
Link to my Power BI file
https://drive.google.com/file/d/194jBF5M8KMLSAcfvzDjeotftdOahtnZG/view?usp=sharing
I am expecting that TopN selection will be affected by other slicers. However, the number of top teams selected will remain unchanged.
Your ranking is working as designed. i.e.
Selecting top 3 and 1930 returns 7 results as you have 5 teams all scoring 7 goals. Look at the table below for an explanation.

DAX Measure Default to MAX Date

I'd like to adjust these two measures so they default to the max year in the dataset when there are no filters applied i.e. without having to click on 2017, how can I have the cards default to the values for that year (or whatever the max year would be dynamically)?
Create a measure with this below code and just adjust the table and column names as per yours.
max_year_sales =
VAR max_year = MAX(Orders[yr])
RETURN SUMX(
FILTER(
Orders,
Orders[yr] = max_year
),
Orders[sales]
)
Now add this measure as a Card in the report. Initially it will show the Sales for latest year. And after that, if you select a row in matrix, the value in Card will change accordingly. See the initial data and data after selecting a row in the Matrix in the below image-

Power BI slicer OR condition

The interaction between two slicers in Power BI gives me output with AND condition.
Example: If I selected the year 2020 and company ABC, the output would be all the data from company ABC in the year 2020.
But I want the two slicers to work with OR condition.
I have used this Dax
Include = (MAX(Table1[Column1]) = SELECTEDVALUE(Col1[Column1])) +
(MAX(Table1[Column2]) = SELECTEDVALUE(Col2[Column2]))
But the problem with above Dax I have not selected anything in slicer ( ALL by default) it is showing me a blank visual. What am I doing wrong?
let me guess you have a table "or_slicer_main_table" with Year, Company and some other columns. Now create 2 new table where the first one will contain the distinct list of Year from table "or_slicer_main_table" and the second one will contain distinct Company list from that same table.
New custom Table 1:
or_slicer_year_list =
SELECTCOLUMNS(
'or_slicer_main_table',
"YEAR", 'or_slicer_main_table'[year]
)
New custom Table 2:
or_slicer_company_list =
SELECTCOLUMNS(
'or_slicer_main_table',
"company", 'or_slicer_main_table'[company]
)
Do not establish any relation between those 3 tables.
Step-1: Create Year slicer using the newly created "or_slicer_year_list" table.
Step-2: Create Company slicer using the newly created "or_slicer_company_list" table.
Step-3: Create these following 5 measures in your table "or_slicer_main_table"
1.
year_current_row = max('or_slicer_main_table'[year])
2.
year_selected_in_slicer = SELECTEDVALUE(or_slicer_year_list[YEAR])
3.
company_current_row = max('or_slicer_main_table'[company])
4.
company_selected_in_slicer = SELECTEDVALUE(or_slicer_company_list[company])
5.
show_hide =
if(
[year_selected_in_slicer] = [year_current_row]
|| [company_selected_in_slicer] = [company_current_row],
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "or_slicer_main_table"
Final Step: Now just add a visual level filter for the measure "show_hide" and set value will show only when "show_hide = 1".
The final output will be something like below image-
Can you try using "IN VALUES" instead of "SELECTEDVALUE"
So your DAX should be
Include = (MAX(Table1[Column1]) IN VALUES (Col1[Column1])) +
(MAX(Table1[Column2]) IN VALUES (Col2[Column2]))
SELECTEDVALUE function returns the result only if single value is selected in slicer in case of multiple selection it will return Blank(). Thats in the case when nothing is selected (which is similar to all selected) has multiple values in set and so SELECTEDVALUE fucntion will return Blank(). This can be handled by using "IN VALUES" function which can return a set of all selected values.

Need to limit the date in a slicer by today's date in Power BI

I am building a report in Power BI Desktop, created a slicer - YearMonthSort - which has data selection by Year-Month
Plz, see the screenshot below:
My goal is to limit data in this slicer as -
2015-07 to today's date
(whichever it will be when users will look at the data,
in the same format - "YYYY-MM")
In the "Filters" section I can select my starting year as 2015-07,
but having problem setting today's date.
I tried to create the new Measure, but not sure where to place it,
or, may be there is another way to perform this:
IsToday = FORMAT(TODAY(), "mm/yyyy")
I only just started to learn this,
Thank you for help in advance!
You can do the following:
I am assuming that you are using a calendar table that is joined to your fact table on a date field and that your year sort column is calculated with reference to the 'date' field in your calendar table.
Assuming, this is true you can create a calculated column that will flag whether or not the date field is before or after today. This can be achieved by using the following DAX:
IsToday =
SWITCH (
TRUE (),
'Calendar'[Date]
<= NOW (), 1,
0
)
Then, in your visual add a 'Visual Level Filter' using this new column and set it to 1.

Power bi - Use Slicer selection in filtering data

I am new to Power bi but i want to use Slicer(user selection) while filter data with comparison by 'Greater Than' instead of equal to.
I have data of devices with LastUpdated date column. and slicer with few list of dates for 15 days gap (calendar would be better but as it is not available yet sticking with dates list)
When user select a date in Slicer i want to filter the data whose Lastupdated Date is greater than equal to selected date. How to achieve this? tried columns,measures..
Any help is appreciated.
I think you can create a measure that links the Date list table and the Device table, even if there is no relationship between them. However the measure must be present in your visualization otherwise the slicer will not affect it.
I've created a measure that calculates the maximum date for those rows which last update date is greater or equal than the slicer selection.
CalculatedLastUpdate =
CALCULATE (
MAX ( DeviceTable[LastUpdate] ),
FILTER (
DeviceTable,
DeviceTable[LastUpdate] >= MINX ( DateList, DateList[Date] )
)
)
DateList - a table containing a column [Date] with you date range.
DeviceTable - a table containing device data.
Now you can delete LastUpdate column from your visualization in order to avoid two columns with the same data.
Let me know if it helps.
I don't know about earlier , but now you can modify the date slicer to do as "after" the given date (you can do so by clicking on the icons present in the rightmost side of the slicer visual itself , wher you can select mode of slicer as between , after ,list , dropdown etc.)...which I believe means that you get all data for dates greater than the selected dates for the given column used in slicer which in your case will be LastUpdate.