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

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)

Related

calculated column stops working when exdternal filter used

I have some Fact Revenue, I am trying to group by Conca, and display the values only if negative…
For doing it I have this calculated column:
=
VAR name1 = Revenue[Conca]
VAR name2=
CALCULATE (
SUM ( Revenue[CostOfQuality] ),
FILTER ( Revenue, Revenue[Conca] = name1 )
)
RETURN
if (name2>0, 0, Revenue[CostOfQuality])
It works:
(highest value is 0 as expected):
Now...
If I drag fiscal year it stops working:
Why is it that I see numbers higher than 0?? (I want it to still work even if I bring other filters...)
a calculated column is computed computed once on the whole dataset after the data are loaded, and is basically a "static column".
Whatever the expected result, you are looking for a measure, which gets computed in the current context
Calculated columns and calculated tables are different from measures, since they are static: You can filter them, but they don't recalculate on filter changes.

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

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"
)

Power BI counting double values

I'm trying to create a measure in Power BI that will count doubles as a single value and then later add them all up to see how many doubles we have. Here is an example:
Each customer whose name shows up more than once should be counted as 1
Bonus question, how can I make a measure which will count customers whose name only shows up once (example name - Sarah).
Thanks in advance!
If you want to count the customers distinct you can use:
CountCustomers = DISTINCTCOUNT([Customer])
if you want to count the doubles, you can use:
Doubles = COUNTROWS(FILTER(SUMMARIZE(CusTable, CusTable[Customer], "countC", COUNTROWS(CusTable)), [countCol] > 1))
First I summarize it to a table with the name of the customer and how often it is appearing in the table
Next I filter this table by all rows bigger than 1
Last I count the rows
You can create this below measure to check the customer is there for once or multiple time in the list. This measure will return 1 if the customer is there for once and 0 if the customer exists for multiple time.
is_unique =
VAR current_customer = MIN(your_table_name[customer])
VAR customer_count =
CALCULATE(
COUNT(your_table_name[customer]),
FILTER(
ALL(your_table_name),
your_table_name[customer] = current_customer
)
)
RETURN IF(customer_count = 1, 1, 0)
This will return 1 for customer- Sarah and David. For all other customer, it will return 0. Now, if you add the above measure to a Card and apply SUM on the measure, it will return value 2 which is basically your customer count with single existence.

Measure with Sum using Calculate and IF not showing totals correctly in power bi

I have a requirement in power bi to display the amount value only for the minimum date selected by the user in the slicer. So created below measures..
For capturing the minimum selected range
StartDate = CALCULATE(min(‘DATE’[DATE]),ALLSELECTED(‘DATE’[DATE]))
For Displaying the amount only for the minimum date.
OP = if(SELECTEDVALUE(‘DATE’[DATE]) = [StartDate],
CALCULATE(sum(MEASUREMENTS[OPENING_BASE_VAL]),DATESBETWEEN(‘DATE’[DATE],[StartDate],[StartDate])),0)
I am getting desired output, but the grand-total for this measure becomes 0 as show in below image. Any help much appreciated.
You are getting 0 in the total because
SELECTEDVALUE(‘DATE’[DATE]) in your second formula returns blank, so your IF expression reads as " IF BLANK = [Start Date]", which is always false.
SELECTEDVALUE is a syntax sugar for the following code:
IF HASONEVALUE(DATE’[DATE]) then return Date[Date] else return blank. Since in the total you have many values (all dates), you are getting a blank.
To solve the issue, you need to iterate by dates.
OP =
VAR StartDate = [StartDate]
RETURN
SUMX(
VALUES(Date[Date]),
IF(Date[Date] = StartDate, CALCULATE(SUM(MEASUREMENTS[OPENING_BASE_VAL])), 0))
Here, we first save start date into a variable to avoid calculating it multiple times. Then we create a list of dates using VALUES function, and use SUMX to iterate this list, date by date. If currently iterated date is a start date, then values are summed, otherwise you get zero.
If instead of zeros you can use blanks, you can use a more optimal/faster code:
OP =
VAR StartDate = [StartDate]
RETURN
CALCULATE(SUM(MEASUREMENTS[OPENING_BASE_VAL]), KEEPFILTERS(Date[Date] = StartDate) )
Here, we calculate sums only where dates are equal the start date. Since there is no iteration, and there is no "IF", the code is much faster. The total will be the same, only line items will show blanks instead of zeros.

How to show the total values of rows in a Matrix with number value having my columns values as percentage

I've started to manage PowerBi from a couple of weeks so i'm a little bit confused about some things.
My problem is that i need a Matrix in my dashboard with percent values but i want the total in number value because the total of a percent of row shows me always 100% and i dont know about the number i'm working
This is my Matrix with percentage values
This is how i want the total of row returns me but with the columns values ins percentage
I've tried to make a measure counting the values
COUNT(OPSRespuestas[answer])
After that turn off the total of rows and add this measure to the values in my matrix but this is what i get
This is my table after trying add a measure with the total
It returns me the total for each of the columns and not the total of all my rows.
These are the tables i'm working with
This my top header values
This is my left header values
The answer column is what i need to count
This is my relationship between this 3 tables although i have many more intermediate table aside from this 3 as you're going to see in the next picture:
My relationship tables
So finally what i need is that this matrix shows me the total of answer in percentage for each of departments and group of questions and then show me total by department but with number value
The problem you are experiencing has to do with context. Each row is seen as it own total population hence the 100% total. Each column in this row is evaluated against the total of that row to provide a percentage value.
In addition to adding a custom measure to replace the total, you could also consider computing a percentage against the grand total of all dimensions. This means that each cell gets evaluated against the the total of all rows and columns. In this ways the cell value would change compared to your first table but the row total does not evaluate to 100% anymore.
SUM ( [Value] ) / CALCULATE ( SUM ( [Value] ) ; ALL ( 'Your Table' ) )