Power BI: Calculate Opposite Row Count from Measures - powerbi

I have a dashboard with a table that shows row counts for a database table according to their codes.
I have divided these counts between measures using CALCULATE to determine whether a row in the table contains a specific code. For example,
measure1 = CALCULATE(COUNT(table[id]),table[code]=1)
I made 5 measures with specific codes so that they are shown in the table as columns. I also use ANDs and ORs in the measures when comparing two codes, if more complex logic is needed.
Now, I have an idea for a new measure. I want to count all of the rows except the rows from the 5 previously created measures. How can I use those 5 measures in the logic of my new measure? Or, is there any other way to solve my problem?

You wouldn't be able to reference your 5 previous measures directly in your new measure, since those measures result in a number (count), but don't give you any information about the logic behind how that number is calculated.
To accomplish what you want, you basically just want to negate the logic from those 5 measures directly in your new measure. For example, if 2 of your previous measures look like the following.
Measure 1 = CALCULATE(COUNT(table[id]), table[code] = 1)
and
Measure 2 = CALCULATE(COUNT(table[id]), table[code] = 2)
Then your new measure, which calculates the number of rows NOT counted in the above measures, would look like the following.
Measure 3 = CALCULATE(COUNT(table[id]), NOT(table[code] = 1), NOT(table[code] = 2))
You would do this negation with the logic from all 5 of your previous measures, rather than just the 2 given in the example above.

Related

How to create a measure that goes first through equipment and then sums it all

I have a database that has some values as "Date", "StopedTime", "PlannedProductionQtt" and "PlannedProductionTime". These values are sorted by equipment, as the little example below.
What I need to do is divide PlannedProductionQtt by PlannedProductionTime and then multiply by StoppedTime. After this, I want to make a graph that shows it day by day.
At first I thought it was easy, made a new measure PlannedProductionQtt/PlannedProductionTime = SUM(PlannedProductionQtt)/SUM(PlannedProductionTime) (assume it worked without the table name).
And then I did another measure Impact = SUM(StoppedTime)*PlannedProductionQtt/PlannedProductionTime.
When I plotted a clustered column chart with this measure in values and a the day for the axis, at first I thought I had nailed it, but no. The BI summed all of PlannedProductionQtt and divided by the sum of all PlannedProductionTime for the day, and multiplied by the sum of the StoppedTime of that day.
Unfortunately, this gives me wrong results. So, what I need is a measure (or some measures) that would make it equipment by equipment and the sum it by day.
I don't want to make new tables or columns for theses calculations because I actually have 32 items of equipment, 3+ years of data, more than 1 classification of StoppedTime and the databases for PlannedProduction use more than one line per day per equipment.
To make it clear I added one column as Impact to show the difference.
So, if I sum the column Impact per day, I would have for day 1,2 and 3 the results 110725, 61273 and 220833.
However, if I sum first all the PlannedProductionQtt for day 1, divide it by the sum of PlannedProductionTime of day 1 and multiply it by the sum of StoppedTime of day 1 (which is how PowerBi is calculating) I will have 146497.
I inserted the difference in the table below to make the differences clear:
As Jon suggested in a comment, here is what solved my needs:
measure_name = SUMX( source_table , DIVIDE ( source_table[PlannedProductionQtt] , source_table[PlannedProductionTime] , 0 ) ) * SUM( source_table[StoppedTime] )
You have two different types of data you want to divide there, time and int, so you would probably need to unify that. Easiest way to do it would be from the Transform data panel, selecting the column and changing its
format
The division is done fairly easily, can you try creating a new measure as follows
measure_name = CALCULATE(
DIVIDE(<source_table>[PlannedProductionQtt],
<source_table>[PlannedProductionTime],
0)
* <source_table>[StoppedTime]
)
Then it's only a matter of using it as values in a graph and the 'Date' column in x axis.

Calculate % of two columns Power BI

I want to calculate % of two columns which are already in %.
I want to calculate formula like
Target achieved= ACTUAL/TARGET
But here is ACTUAL is already a measure/calculated metrics so I'm not able to divide these two columns.
Any help would be appreciated..
Make sure both target and actual are actually numbers and not strings. You can do it in transform data (aka Power Query) part, before data is loaded into the report.
After that you should be able to create the measure you want, e.g. something like that:
UPDATE : What happens if Actual is not a column, but a measure?
If Actual measure is based on the columns in the same table as target you shouldn't have a problem. You cannot combine measure and column in the same formula. Measure is an aggregated field and needs to be grouped by another field (if you are familiar with SQL,think of SUM and GROUP BY). Coming back to your problem, you need to create measure out of "Target" column as well (notice I have in the formula SUM('Table'[Plan]) which makes it a measure). Than you can use both of them in the formula, but of course you need to "group" them by something(e.g. date) otherwise it will just show you a total.

Calculated column in Power BI that repeats different sums based on conditions in 2 other columns

I need a calculated column based on conditions in two columns (Business Unit Number in both tables and L1/Account Categories in 1st table and the second table) which sum and then repeat for several rows before the conditions change and a new sum is repeated for several rows and so on. The L1/Account Categories columns have different names because it's the raw data.
For example, any time ASSETS and 111 appear in the same row, I would want to use those as conditions and with the sum of all of the other matching rows in a new column and the sum would repeat each time both conditions appeared in the same row. Any time P/L and 111 appear in the same row, that would be a sum of all other P/L and 111 appearances in the dataset (about 1000 rows overall)... and so on.
I've tried formulas with DAX using FILTER, SUMX, nested IF statements and also tried the Power Query language among other attempts. Maybe I have to create one or more than one new table? If you need to take a look at a few of my attempts, just let me know.
The top image is how I imagine the output will look in the power query editor and the bottom image is a sample of the source data.
This last pic is from Tableau - I need to make a table in Power BI which essentially a duplicate of this image. The last 2 columns are pulling from different tables.
This should be very simple to achieve with relationships and measures - no need for calculated columns or power query merges. You need to build a relationship between these two tables. In fact, I would introduce a third table in your model for Business unit.
The limitation of Power BI model relationships is that they can only be based on a single column. So to build a relationship between these two tables you would have to add a calculated column in both of them that would contain both a BU and the financial statement line, for instance: JoinCol = CONCATENATE([Business_Unit_Number], [L1]). Then you could create a relationship and do what you want.
The better (one that I would recommend) approach would be to separate Business Unit into a separate table and have relationships built like this:
Then all you have to do in your visual is drag Business unit name from the BU table, L1 from the FS Lines table and a measure to sum the amounts Amount = SUM('Financial Data'[Rolled Up Detail]).
Here is a working sample: https://1drv.ms/u/s!AmqvMyRqhrBpgtUT5HKnZP1U3Gzc9w?e=en91dV

Create Multiple Calculated columns using one DAX formula

Is it possible to create 2 different columns using one DAX Expression?
I have 2 column, for example Work Done this month and Invoiced Amount. I want to create 2 columns using these.
Work Done - Invoiced and return only positive values (Deferred)
Invoiced - Work Done and return only positive values (Extra)
Note: I know how to add these columns using 2 DAX formula's here, but I would like to know if its possible with one formula.
Samsple Screenshot below:
I believe it is possible but not within the existing table and it strongly depends on the context on which your are calculating. When your calculation is performed on a row level, ADDCOLUMNS could help you out. It allows you to create a new table and add multiple calculated columns.
https://learn.microsoft.com/en-us/dax/addcolumns-function-dax

Power Bi Desktop - How to add values between tables?

I'm trying to create a column that has a total of values between 3 columns from 3 tables. How would I go about doing this?
The 2 tables are tables of values that share an id, and they are both linked to a table of account by Id. The goal is to add up 3 columns, and place it into a table grouped by the Id.
I've attempted summing them, trying to use the USERELATIONSHIP function, and creating a relationship between them. It seems to give very inaccurate results, as if it's summing all of the totals together, and passing them to each Id. That, or it won't let me use the column, as if it never existed.
EDIT: General Idea of what I'm trying to do (Lines should be pointing to Account's Id column, but I messed up the lines)
EDIT 2: I also forgot to illustrate or mention. There are more columns with information in each table that can't be summarized for each account preventing me from just merging the table together.
Make sure your data model looks like this (change names as you please, but the structure must be the same):
In dimensional modeling, your table "Account" is a Dimension, and both fee tables are Fact tables. The operation of combining data from multiple fact tables that share the same dimension is called "drill-across", and it's a standard functionality of Power BI.
To combine fees from these tables, you just need to use measures, not columns. This article explains the difference:
Calculated Columns and Measures in DAX
First, create 2 measures for the fees:
Fee1 Amount = SUM(Fee_1[Amount])
Fee2 Amount = SUM(Fee_2[Amount])
Then, create a third measure to combine them:
Total Fee Amount = [Fee1 Amount] + [Fee2 Amount]
Create matrix visual, and place Account_ID from the Account table on the rows. Then drop all these measures into the matrix values area, like this:
Result:
Of course, you don't have to have all these measure in the matrix, I just showed them for your convenience, to validate the results. If you remove them, the last measure still works: