Change grouping column based on slicer selection - Power BI - powerbi

I have a data set and a mapping table as below.
In Power BI, I created a slicer dropdown containing words "Finance Lens" and "Business Lens", This is created using table "Lens" and column "Lens Type"
Based on the selection, I want the grouping to change in the below visuals.
I created a new column as below :
Selected_Lens = If(SELECTEDVALUE(Lens[LensType],"Business Lens")="Business Lens",MappingTable[Business Lens],MappingTable[Finance Lens])
But it is not working... Any idea would help.

Related

Replace values in cell with DAX coding in Power bi

I have my data(file name - Data) which I have imported in power bi with a column named values
values
ext
int
safety_int
outside_training
gap_fill_int
so it is a large data, and it contains more than 2k categories , what I want is, to create a new column in power bi where blanks should be replaced with target_emp, and all other values(ext,int,gap_filling_int etc.) should be replaced with non_target_emp.
Please help me to do that in power bi.
In powerbi transform ->
Add Column:
if Text.Trim([category]) = "" then "target_emp" else "non_target_emp"
You could add a conditional column in the data model (sorry that I dont have an English screenshot for this):
Add column
Select conditional column
Add criteria to selection
#1 DAX
calculatedColumn= SWITCH(TRUE(), Data[Column1]=BLANK(),"target_emp", "non_target_emp")
#2 using PBI's binning
go to report view->click on the table->column name-> New Group

Power Bi Extract a Column value based on some another field in different Table

I have a Power BI table with some columns as given below:
Table1 - Columns(Project, Program, Name, Attribute, ID)
Example of table1:
Now I have a different measure which is used to view Power BI report. It also has some fields as given below:
Measure1 - Columns(Project, Name, Attribute, and few more)
Example of Measure:
Now I want to add ID (which is available in Table1) as Measure1 is being used to view report. How can I display ID based upon Name and Project.
Can anyone guide or help how to solve it?
If you can do this in your source Database using left join between this 2 tables.
If not, then you can use virtual relationship in DAX:
Display_ID = CALCULATE(min(Table1[ID]), TREATAS(VALUES(Table1[Project]), Measure1[Project]), TREATAS(VALUES(Table1[Name]), Measure1[Name]))

Power BI - Filter table using slicer to match within concatenated column

I've looked all over and can't find a way to do this.
In the table, I have all postcodes throughout the UK and a calculated column that concatenates from another table the products' that have been purchased in that location.
I need to filter the table to hide rows where the value selected in the slicer is in the concatenated column. I think this needs to be a measure and have tried using CONTAINSSTRING but nothing seems to be working.
Latest measure that I have tried is:
=IF(CONTAINSSTRING([Concatenated Values],[Selected Slicer Value]),"Hide","Show")
Does anyone have any ideas?
Example tables and expected results:
You can link the "another table" (the one with the products (not concatenated) per area) to the Area table.
Just change the filter option to: cross-filter direction: both
Then you can use it in your slicer.
Follow these below steps to achieve your requirement.
Let-
Your Slicer Table name: Table1
Your Details table name: Table2
Step-1: Create this following measure in Table2
show_hide_this_row =
FIND(
SELECTEDVALUE(Table1[products]),
MIN(Table2[products]),
,
0
)
Step-2: Add visual level filter using measure "show_hide_this_row" as below-
The output will be as below-
This functionality only works perfect when single selection is enabled in your slicer.

Slicer Only Show Month / Year and Filter On That

I have a table with a value ReportDate, which is in the format '03/01/2020'. I want to create a slicer in my Power BI report that displays only the format '03/2020' and the user can then select the value of the month and year to display, and it will display the data for that month (regardless of the day value). How would one go about doing this? I know technically I can add a new column in the database table, but unfortunately I do not have access to changes in the database and as such, would like a Power BI solution.
In the Power Query Editor create a new column with formula
Date.ToText([Date], "MM") & "/" & Date.ToText([Date], "yyyy")
Change [Date] to whatever your date column is called. Date.ToText converts a date time to text, which is then concatenated. You can then filter on that column. For issues like this it is best to have some sort of calendar table.
You can create a new column in using query editor in power bi:
mon_year = left(<column_name>, 3) & Right(<column_name>, 4)
Note: Make sure your are connected to dataset in import mode because in live connection you will not be able to create New Column in Power BI.

How to display Subtraction of two fields and display as a column in PowerBI?

I am using SQL server data base. I need to display total no of nights based on checkindate and checkout date. i am new in Power BI.
I tried by quick measure but it is not working.
You can do this in different ways - calculate the duration in the database, add custom column in M or column in DAX.
In SQL Server use select query like this:
select checkindate, checkoutdate, datediff(day, checkindate, checkoutdate) as duration from table
In M (Power Query) - click Edit queries to open Power Query editor and then Add Column -> Custom column:
Duration.Days(Duration.From([checkoutdate]-[checkindate]))
In DAX - right click your table and select New column:
Duration_DAX = DATEDIFF('Table'[checkoutdate]; 'Table'[checkindate]; DAY)
Note, that depending on your settings, you may have to use comma (,) instead of semicolon (;) in the DAX expression above.