Power BI Calculate sum of column 2 when column 1 = " ? " - powerbi

I want to create two measures that sum up the values of column 2 when column 2 equals column 1's parameters.
For example I have a column named Current/Reset and another column named Linear Ft. I want to sum up the values of Linear Ft where column 1 = "Current" and then again for "Reset."
I continue to get errors when I try and write the formula. Any help is much appreciated!

First of all you don't need explicit measures for this. It's the default behaviour of Power BI to sum up numbers (aka. implicit measure), and if you filter Linear Ft. by the (unique) values of Current/Reset you get your desired result.
However, if you still want to have separate measures for this, use CALCULATE()
Current Sum =
CALCULATE(
SUM('Table'[Linear Ft.]),
'Table'[Current/Reset] = "Current"
)
Reset Sum =
CALCULATE(
SUM('Table'[Linear Ft.]),
'Table'[Current/Reset] = "Reset"
)

Related

How to find MAX of Summarized numeric column in Power BI

I need to create a Measure to mark the row with 1 or 0 based on maximum count of a column Country. The country which has maximum count should be marked with 1 else 0. I am doing this in three steps. First finding count of all countries using SUMMARIZE function and then in second step I am finding the maximum value from the table created in the first step using SUMMARIZE function again. In the third step comparing the value of 2 step with count of each country, if they are equal then return 1 else 0.
Below is the DAX query which is giving wrong output :
CountOfState =
var t1 = SUMMARIZE(customer,customer[State Province],"CountOfStates",count(customer[State Province]))
var t2 = SUMMARIZE(t1,"countofstatess",maxx(t1,[CountOfStates]))
var v1 = CALCULATE(count(customer[State Province]),ALLEXCEPT(customer,customer[State Province]))
Return
if(v1 = t2,1,0)
--There is something wrong in var t2. t2 is giving wrong values because it is filtering out the values and I cannot figure out how to use ALL function for table expression.
Below is the wrong output :
Expected output :
As Texas has the highest count 3 this should be marked as 1 and others as 0.
Thanks in Advance.

PowerBi Distinctcount not working properly with 3 measures

I am having an issue using the Distinctcount function in DAX. I have a table with a total of 1,154,493 rows. I have a measure created to count the number of distinct values in column 1. I have another measure created to count the number of distinct values in column 1 with filters. I have a 3rd and final measure created to count the number of distinct values of column 1 with different filters. The issue I am running into is the count of measure 2 + measure 3 should equal measure 1 however added together they are GREATER than the value of measure 1 which is just a grand total. How is this possible? Unfortunately I can't share the table but below is the code I am using for the two measures:
Measure1=distinctcount('Table1'[Column1])
Measure2=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 1,'Table1'[CTest2] = "07")
Measure3=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 2,'Table1'[CTest2] = "07")
I am at a loss. Thank you in advance!!
For troubleshooting you should identify values of Column1 with Measure2 and Measure3 > 0, those are being added twice.

Manipulate the total row to only sum the first row of every unique order in a list

This might be a strange question and not sure if it is possible to accomplish this with a Power BI table. My goal is to make the total row display the sum of the first row (Operation flag = 1) of every order in a list.
Logically the summarizing total row would produce the below result by summarizing all the rows in the "Manufactured Qty" column. (The below is just a manually created example in Excel to illustrate)
The desired DAX logic should instead produce the below result i.e. summarizing the quantity of every "Order no" with "Operation flag" equal to 1 in the total row.
Best regards,
Rubrix
One way to do this is to use a measure instead of the column. In this measure, use HASONEVALUE to check if the value is for a data row or for the totals row and either return the sum of all rows (for the normal case) or the sum of the rows where Operation flag = 1 (for the totals).
Manifactured Qty Measure =
var allRows = SUM('Table'[Manifactured Qty])
var firstOnly = CALCULATE(sum('Table'[Manifactured Qty]),'Table'[Operation flag] = 1)
RETURN IF(HASONEVALUE('Table'[Manifactured Qty]), allRows, firstOnly)

Return TOP 5 values in column by category

I'm looking for good solution to be able to present on a table visual in Power BI TOP 5 highest values out of column X in table, grouped by User name in column Y of the same table.
So for each distinct user in column Y I need to show top 5 values in column X in descending order.
You can get the Top 5 details by using the RANKX function:
Rank = RANKX(CALCULATETABLE(Table,ALLEXCEPT(Table,Table[Column Y])),Table[Column X],,DESC,DENSE)
The above calculation will give you the dense rank. If you want the normal ranking use "skip" instead of "dense". Once the rank is calculated, you can filter the rank value for <=5 and you should be able to get the desired output.

PowerBI - Running Total on Time-Independent Data Column

I was attempting to employ the formulas here to calculate a running total of a column in PowerBI. However, my data is time-independent. In addition, every other running total calculation I've seen for PowerBI has been in reference to a date field. The target column is a "Frequency" column, and represents the estimated frequency of the event represented by each record. How do I generate a cumulative total of these frequencies, from lowest frequency to greatest? This is used to generate an exceedence curve for the consequences of events based on the running frequency total, called an F-N curve.
Per this site: https://www.daxpatterns.com/cumulative-total/, I was able to generate the following measure:
Measure_cumF =
CALCULATE (
sum([content.F]),
FILTER (
ALLSELECTED( Sheet1),
Sheet1[Content.N] >= MIN ( Sheet1[Content.N] )
)
)
"MIN" allows the cumulative sum of "Content.F" to start at the row containing the highest value of the desired sorting list, in this case "Content.N". "MAX" will start the cumulative sum at the row containing the lowest value of "Content.N".
"ALLSELECTED" applies the current filters to the measure. Replace with "ALL" to have a static value that always returns the cumulative sum of the entire column.