Create Multiple Calculated columns using one DAX formula - powerbi

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

Related

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

When to use calculated field vs measure in Power BI?

Power BI allows to add calculated field and measure to table. Both create new column and allow me to add DAX formula.
When to use calculated field vs measure in Power BI?
The most important difference is that calculated columns are calculated once when the dataset is loaded. Their value does not change later, i.e. it is not affected by slicers for example. Measures are dynamic. They are calculated whenever necessary, thus they will respond to slicers in the report.
I would recommend to read this article - Measure vs Calculated Column: The Mysterious Question? Not!
Rule of thumb: If you want to use it in a filter or a slicer, put it in a column. Otherwise, you can create it as a measure.
Link: https://learn.microsoft.com/en-gb/learn/modules/dax-power-bi-add-measures/5-compare-calculated-columns-measures
Regarding similarities between calculated columns and measures, both are:
Calculations that you can add to your data model.
Defined by using a DAX formula.
Referenced in DAX formulas by enclosing their names within square brackets.
The areas where calculated columns and measures differ include:
Purpose - Calculated columns extend a table with a new column, while measures define how to summarize model data.
Evaluation - Calculated columns are evaluated by using row context at data refresh time, while measures are evaluated by using filter context at query time.
Storage - Calculated columns (in Import storage mode tables) store a value for each row in the table, but a measure never stores values in the model.
Visual use - Calculated columns (like any column) can be used to filter, group, or summarize (as an implicit measure), whereas measures are designed to summarize.

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:

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