how to store measure value in table in Power BI? - powerbi

I have measure that store the Slicer selected value. now I want to store measure value in new table but not getting success. Please help here.
Also i want to know if there is a way to store slicer selected value in table directly.
below syntax i used to store slicer selected value in measure
Slicer_Value = selectedvalue(column)
Regards,
SK

You cannot store a slicer selection in one of your model tables (either in a new calculated table or a calculated column on an existing table) since these are only calculated when your data is loaded or refreshed rather than every time you make a slicer selection.
However, it's highly likely that there is another way to do whatever it is you are ultimately trying to achieve by another method.

Related

Dynamic filtering based on selected value in slicer in Power BI

I am trying to create a calculated table where the data is being taken from another table and calculating the average based on the username, total average and variance between the 2 of these columns.
To create a table, I used the below DAX in Power BI which calculated the average based on the username.
scanner_speed_average_calculation =
SUMMARIZE(scanner_speed
,scanner_speed[user_name]
,"Average"
,AVERAGE(scanner_speed[order_processed]))
To calculate the group_average I used the below DAX:
group_average =
SUMMARIZE(
scanner_speed
, "Group Avg"
, average(scanner_speed[order_processed]))
And finally to calculate the variance, I used this query:
Variance = scanner_speed_average_calculation[Average] - scanner_speed_average_calculation[group_average]
Below is an outcome of these calculations.
I want to be able to make these calculations dynamic based on the selected value from the date. The table where I am taking these calculations do have the date value. I want to be able to use date range in slicer and I want these values to change based on the selected date range. I tried few things with Filter, Selectedvalue but I am not sure if I used them correctly.
Below is a main table where I took all these calculations from.
Below is a visual of where I want to group_average and variance. I want to be able to use date range and these columns should change accordingly.
Any idea or help will be appreciated. If possible then please put the entire formula. I am still a newbie in the world of DAX. Thanks in advance
power bi file
If you want a calculation to depend on a slicer, you need a Measure, not a calculated column or calculated table. Calculated columns and calculated tables are generated on refresh and physically stored in your model, so the slicers can filter them, but the slicers can't change the value of the calculations.
Measures are not persisted, but are calculated as needed based on changes to filters and slicers.
If you simply add add a measure
AverageOrdersProcessed := AVERAGE(scanner_speed[order_processed])
and put that on a visual that groups by user_name, you will get a the AVERAGE(scanner_speed[order_processed]) for each `user_name'.

Power BI DAX - Measure to change name of row value

I need some help creating a measure to change the name of "FROM_USER" in the slicer here.
I think I need to use the function SELECTEDVALUE, but I have not managed to get it working.
So, the column has only two values, CRAWLER and FROM_USER.
Any suggestions would be helpful!
See picture
Measures can't be used as slicer values. If you want the column values to be changed and yet to be used in a slicer, you need to create a calculate column to change that.
Column = IF('Table'[Column1]="FROM_USER","desiredValue","CRAWLER")
If you are really keen on using a measure to slice, you need to build a disconnected table and follow the method described here. But the performance will take a hit depending on how complex your data model and calculations are.

Reference variable tables using dynamic table names - Power BI, DAX

I have a measure whereby I calculate some data based on a slicer value. The slicer determines which table I get my data from e.g. SUM(TableA[sales]) or SUM(TableB[sales]). (Each of my tables is of the same structure).
I'd like to be able to set up a variable to dynamically change (with my slicer) which table I'm referring to.
Right now I have:
// Set __table to a stored string representation of the name of the database
// This seems to work
VAR __table = SELECTEDVALUE( AllTables[TableNames] )
// Evaluate the sales column of my variable table
// This doesn't work due to 'Cannot find name sales'
CALCULATE(SUM(__table[sales]))
I guess what I'm after is a way to have the slicer change the referenced table in my measures (with all of the columns being the same for each table).
I'm new to Power BI and I've been struggling with this for several days now. I'd really appreciate any help with either the method I'm attempting or any alternatives.
If you have small amount of data in each table, you can merge them all together as they are in same structure. Just add an additional column with reference of the Table name. Now you can create your Slicer using the new column and it will hold all table names in the list. Now, if you change table name in the slicer, your visuals will show results based on data from that respected table.

When to use calculated field vs measure in Power BI?

Power BI allows to add calculated field and measure to table. Both create new column and allow me to add DAX formula.
When to use calculated field vs measure in Power BI?
The most important difference is that calculated columns are calculated once when the dataset is loaded. Their value does not change later, i.e. it is not affected by slicers for example. Measures are dynamic. They are calculated whenever necessary, thus they will respond to slicers in the report.
I would recommend to read this article - Measure vs Calculated Column: The Mysterious Question? Not!
Rule of thumb: If you want to use it in a filter or a slicer, put it in a column. Otherwise, you can create it as a measure.
Link: https://learn.microsoft.com/en-gb/learn/modules/dax-power-bi-add-measures/5-compare-calculated-columns-measures
Regarding similarities between calculated columns and measures, both are:
Calculations that you can add to your data model.
Defined by using a DAX formula.
Referenced in DAX formulas by enclosing their names within square brackets.
The areas where calculated columns and measures differ include:
Purpose - Calculated columns extend a table with a new column, while measures define how to summarize model data.
Evaluation - Calculated columns are evaluated by using row context at data refresh time, while measures are evaluated by using filter context at query time.
Storage - Calculated columns (in Import storage mode tables) store a value for each row in the table, but a measure never stores values in the model.
Visual use - Calculated columns (like any column) can be used to filter, group, or summarize (as an implicit measure), whereas measures are designed to summarize.

Power BI / DAX return values from table from rows filtered out by slicer

I have a table visualisation that shows the populations of countries and a toggle switch that flips between 'sold' and 'unsold'. (This works with a measure that checks is a country is present in a sales table and assigns a 1 or 0 which is then used as a filter on the table visualisation).
Various slicers in the dashboard are used to filter the data model and retain the details of sales. When 'unsold' is selected therefore, the relevant countries are already filtered out of the countries data table and it is not possible to display them with their populations.
At the moment the workaround is to use a duplicate countries table that only has a one way filter, so that the rows remain regardless of filtering. This means that other slicers which interact with the rest of the data model don't filter the table visualisation as desired.
I am sure this must be possible using some combination of CALCULATE(), FILTER() and ALL() but I haven't managed to achieve this.
N.B. I can force the unsold countries to appear in a table visualisation using a constant measure (with formula: measure_name = 0) in a column .
Apologies if this is not very well explained, any help much appreciated.
Thanks for reading,
S
Image attached to (hopefully!) explain problem better.
Real scenario is more complicated hence not screenshotting from PBI.