DAX How to Get a Row Number Value - powerbi

I have a table visualization in Power BI.
I am trying to get a row number added for my table.
I am using the following DAX: RANKX(table_1,table_1[customerSK],,ASC,DENSE)
I am getting the following error message:
A single value for column CustomerSK in table_1 cannot be determined.
This happens when a measure formula refers to a column that contains
many values without specifying an aggregation such as min, max,
count...
Does anyone have any suggestions?

Use the DAX formula in a calculated column instead of in a measure.

Related

Power Bi - Cannot find column in a DAX

I am a newbie in PowerBi and I am trying to create a DAX in order to compare a column with different variables in order to attribute some values in order to do some conditional formatting of the cells.
I read that I must had a MIN(), MAX(), ... in the expression but I just want to compare for each value not with the maximum.
Thanks in advance for your help and your time

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 - Unpivot a few columns in a table without interfere the remains columns

So I have this table:
Original Table
I would like to transform the Defect columns into only one without affecting the total of the Inspected column. I've tried the Unpivot the selected columns and brought me this result
Unpivot selected columns
The total of inspected changed from 13 to 52. To solve that problem I've tried to duplicate the table and unpivot only the defects and remaining the inspected in the other table, however I need to make calculations between those tables and both are already related to a third table. Someone has any idea how can I solve this?
Thanks in advance
Add column by example after selecting Attributes, ie Attribute Index.
Calculate count nulls, errors and percentages against the Attribute column total
Calculated Value = SUMX(VALUES(Attribute Index),CALCULATE(MAX(Value)))

DAX way to return summarised data

I hope I'm not missing an easy solution am still getting used to DAX and can't yet find an appropriate logic.
I have a large dataset, >10m rows which I want to test. An identifier column "DocumentNumber" might occur on multiple rows and I want to find where the sum of "Value" over these rows for a given "DocumentNumber" is non-zero.
Tried to use PowerQuery > removed all but these two columns > Group By > DocumentNumber > Sum of Value. However my 32 bit version of Excel appears to run out of memory performing this step Expression.Error: Evaluation ran out of memory and can't continue.
Wrote a DAX measure > Sum of Values and dropped into a pivot table with a view to filtering out the zero values but when I try to drag in the DocumentNumber to rows there are more than a million rows so the table won't render.
Is there a logic I should follow in DAX that would achieve step 2 before bringing it to the pivot table? Can DAX actually create a new table in the data model which is the aggregated and filtered data rather than using a pivot? I believe this is possible in PowerBI but not sure about Excel evironment.

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