Power BI Visuals with Measures only without summing up - powerbi

Situation:
My Report calculates the ranking developments of an accounts in one measure:
Class_Evolution = [Class_Minus_0] & " <-- " & [Class_Minus_1]
Combined with data from the source table the measures show good results per datarow.
The results look like:
...
[Class_Minus_0] and [Class_Minus_1] are measures with X-functions themself that result in a ranking (A,B,C,D) depending on slicer selection.
I also have a measure that counts the rows:
Count Values = COUNTROWS(ExhibitorClass)
This works so far.
Problem:
Now I need to crate visuals with the measures I created. But when I put my measures on a visual they just get summed up:
Need:
I need to built the visuals as in the example below but by using my measured instead of columns.
I have build the report without a slicer on fixed data columns with fixed ranking cutoffs and got a nice result:
However I need to be able to calculate the ranking development with the slicer so I need to build everything with measures.
How should I build my measures to get the visuals I need? Please help me.

Thanks to Andrew, I was able to implement the following solution.
I needed a new Table matching the possible results of the measure:
Then with a VAR variable in a DAX measure the matching values could be counted:
Visual Count Class Evolution =
VAR _rank_evolution = SELECTEDVALUE('Class_Evolution'[Class_Evolution])
return sumx('ExhibitorClass_Details', if([Class_Evolution] = _rank_evolution, 1,0))
The variable was populated form my [Class_Evolution] table and if the measure used on my [ExhibitorClass_Details] details table matched the Class_Evolution it was summed up.

Related

Add Manual Formulas in Power BI Table Visualization

Is it possible to perform calculations based off of the Table Visualization's values? I understand Power BI has the option manually add columns in the data set but that will not work in this example because of how the data is aggregated.
Basically, I would want the option to create a formula next to revenue where I would divide revenue by cost.
enter image description here
As has been mentioned, a measure would be the solution. Something like the following
Measure = DIVIDE(CALCULATE(MAX(Table[Revenue])), CALCULATE(MAX(Table[Cost])), 0)

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'.

Based on slicer selection create dynamic calculated table in Power BI

I’m new to Power BI. Currently facing similar issue explained below in my product development.
I have created power bi modle with below dimensions and facts from adventureworksDW.
Then I created a calculated table, which gives result as sum of sales group by ProductSubCategory and ProductCategory. Below is the DAX for the calculated table.
Now I want to create a new calculated table, which gives me TOPn ProductSubCategory based on the Total sales amount.
Below is the DAX to do this.
and model relationships looks like below.
I want this TOPn rows to be displayed based on filter condition on product category. Something like below.
This works fine when I hardcode the product category value in the DAX itself. But if I want to change this product category values from the slicer selection, then I didn’t get any results.
What you are asking for is not possible as Power BI is currently designed. Slicers cannot affect calculated tables. Calculated columns and calculated tables are evaluated once when the data is first loaded and are static until the data is refreshed.
However, you can get the table visual you want in a much simpler manner by writing the appropriate measure and putting that in the table instead of defining an entirely separate table.
TotalSales = SUM(FactInternetSales[SalesAmount])
The Top N filtering is available in the visual level filters settings.
You can simply use the SELECTEDVALUE function as shown below.
var __SelectedValue = SELECTEDVALUE('ProductSales'[EnglishProductCatogaryName])
return
Filter(
'ProductSales',
'ProductSales'[EnglishProductCatogaryName] = __SelectedValue
)
)

Is it possible to use a slicer as a parameter to a DAX Summarize function?

I have a FactLosses Table, and a DimAccumulation table. I have brought them into PowerBi and I have placed a slicer to choose which accumulation zones i am interested in.
Once the user has selected the zones, i want to perform a group by year on the losses and sum the losses into year buckets. But only on the data that applies to the zones the user picked.
I am using the following DAX code to do the group by like so...
Table = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
The problem is the new table always produces the same result. i.e When i make changes to which accumulation perils should be included it makes no difference to the summation. (it is summing the entire table)
I'd like to use the slicer to filter the fact table and then have the DAX query run on the filtered list. Is this possible?
If you want these tables to be responsive to filters or slicers on your report, then you can't write these as calculated tables that show up under the Data tab since those are computed before any filtering happens.
To get what you want, you have to do everything inside of a measure, since those are what respond to slicers. If you're looking for the max loss year once the grouping and summing are completed, you can write a measure along these lines:
Year Max =
VAR CalculatedTable = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
RETURN MAXX(CalculatedTable, [Losses By Year])
Writing it this way will allow the calculated table to respond to your slicers and filters.

Access to fields in IF sentence in DAX in Power BI Desktop

When I use SUM for example the intellisense of the editor shows me the columns of my table but when I use IF or Switch I'm not shown any column.
In this example of If (https://powerbi.microsoft.com/es-es/documentation/powerbi-desktop-tutorial-create-calculated-columns/) the column between [] works fine but when I put my column between [] I have error
error if
Any idea please?
Regards
I can see you are creating a measure while in the tutorial they are creating a calculated column. Measures and Calculated columns behave different, while creating a calculated column the expression you are using takes the context of each row so you can reference any column directly by [Column].
However measures evaluate in different context so they need an aggregation function to determine the value of your columns.
EXAMPLE: Calculated Column.
Is Red Calculated Column = IF([Color]="Red","Yes","No")
EXAMPLE: Measures.
Is Red Measure = IF(FIRSTNONBLANK([Color],0)="Red","Yes","No")
Note I used FIRSTNONBLANK aggregation function to access the [Color] column from a measure.
The above expression could not work for you depending on your measure, I only posted it for example purposes.
I found the answer
TotalHoras = SUMX(Horas;if(Horas[Tipo]="M";Horas[Duration]/60;Horas[Duration]))
Like #alejandrozuleta says Measures need an aggregation function to works