I am creating a calculated column in PowerBI and am having an issue with the MEDIAN function. Here is my column :
MEAN Lead Time =
VAR PartNumber = 'MyTable1'[Part#]
RETURN
CALCULATE(MEDIAN('MyTable2'[Lead Time]),FILTER('MyTable2','Lead Times'[Part#] = PartNumber))
When I run this code I get the error: Expressions that yield variant data-type cannot be used to define calculated columns.
However, if I change my expression from MEDIAN to AVERAGE it runs no problem. But I want Median not Average, so I am not sure what I need to do...
Thanks in advance!
Related
I have a table like this:
I would like to calculate the result but some of ID column has different calculation formula.
For ID less or equal to 1733 using this formula: Value/3*100 for ID greater than 1733 using this formula Value*100
I tried this way:
Result =
IF('Data'[ID]<=1733,[Value]/23*100)
IF('Data'[ID]>1733,[Value]*100)
But it return an empty value. Anyone could help me please.
Thank you so much
This can be achieved using IF statement by following way by creating a calculated column called "Result"
Result = IF(Data[ID]<="1733",(Data[VALUE]/23)*100,Data[VALUE]*100)
Hope this helps !!
If the [ID] is a text then you can convert it to a number with the VALUE(). When you are trying to convert number to text with quotes then you will get a wrong result for some of values. For text comparison it works like this: "11111"<"2", for number 11111 > 2. For a calculated column it not necessary to write a full column name like 'Data'[ID], you can simply write [ID], because of a row context. DAX will understand that the value and row you are working with is in a current table.
Result =
SWITCH(
TRUE()
,VALUE([ID])<=1733,[VALUE]/23*100
,[VALUE]*100
)
I'm struggling within DAX to find a formula to return the first result. My table is as folllows:
The unique column is Dim_B_ID. So what I really would like to have is to return the first result of Amount ONLY for Dim_B_ID where the column IN is not blank. Im struggling cause I get answers like 3500 (total of the rows) and I can't seem to integrate IF(NOT(ISBLANK( funtion into this. So if someone has a solution for me, I would really appreciate it as I'm not so much of an expert in DAX.
You could try using the following measure:
FirstNonBlank =
FIRSTNONBLANKVALUE(
'Table'[Dim_Date_ID],
SUM( 'Table'[IN] )
)
When put together with Dim_B_ID in a table for example you could visualize FirstNonBlank for every "categorie" like so:
Used slightly modified sample data here:
I practiced to learn Power Bi. I have a data model of size 180931 bytes. I clicked Modelling/New Measure and the put formula Measure 2 = [Kumulatiivinen myynti €]*2. Now if I'm able to edit the formula, put the formula and try to save, the Power Bi freezes. Is there a fix for this bug?
Because this doesnt work. Normally you should get this error message:
The problem is a measure returns a single (scalar) value but your formula is row wise.
Your formula will work in the query editor (M), if you add a custom column with this expression. In the query editor you work row wise.
'M expression
= [Column1] * 2
The result will be a new column where every row has twice the value.
In a measure the correct expression would either be (for all rows):
'DAX new measure expression
= Sum([Kumulatiivinen myynti €]) * 2
or you dont add a measure (you have to add instead a new column), then you can use this expression:
'DAX new column expression
= Sumx('YourTable', 'YourTable'[Kumulatiivinen myynti €] * 2)
which is the same result as the M expression.
I have the following table and am trying to get the sum of a particular column. First Table
I would like to take distinct values for the 'TrackerID' and when durationConnected is greater than 0, then take the value greater than 0. In the end I would like to get the sum which in this case is 7. (See second table):
Second Table
I tried creating another table by doing the following: AnotherTableTest = SUMMARIZE(journal;journal[PhoneNumber];journal[StartTime];journal[TrackerID];"UniqueCalls";DISTINCTCOUNT(journal[TrackerID]);"TimeConnected";Max(journal[DurationConnected])). This didn't give me the expected result.
I also tried using a measure:
MaxAmount = MAX(journal[DurationConnected])
ActualAmount = SUMX(DISTINCT(journal[TrackerID]);[MaxAmount])
Can anyone help me please?
Try creating a new table like this:
newTable = SUMMARIZECOLUMNS('journal'[TrackerID],
"StartTime", MAX('journal'[StartTime]),
"totalDuration",SUM('journal'[DurationConnected]))
EDIT
When [DurationConnected] is the only value that changes for each [TrackerID], this answer is a bit cleaner. I also added 'journal'[Outbound] on OP's request (see comments).
newTable = SUMMARIZECOLUMNS('journal'[TrackerID],
('journal'[StartTime]),('journal'[Outbound]),
"totalDuration",SUM('journal'[DurationConnected]))
I have 2 column; ID CODE, value
Remove duplicates function will remove the examples with the higher value and leave the lower one. Is there any way to remove the lower ones? The result I expected was like this.
I've tried Buffer Table function before but it doesn't work. Seems like Buffer Table just works with date-related data (newest-latest).
You could use SUMMARIZE which can be used similar to a SQL query that takes a MIN value for a column, grouped by some other column.
In the example below, MIN([value]) is taken, given a new column name "MinValue", which is grouped by IDCode. This should return the min value for each IDCode.
NewCalculatedTable =
SUMMARIZE(yourTablename, yourTablename[IDCode], "MinValue", MIN(yourTablename[value]) )
Alternatively, if you want the higher values just replace the MIN function with MAX.