Forum Discussion
Question about creating Lines as totals _FRUSTRATION-
Hi
I have a table named mapping to map a measure called Amount that is a sum(pl_ledger_Amount). This table to map has all the accounts linked to pl_ledger.
I created a line in mapping called Total Gross Margin that is a Formula
Then I have a formula table with the formula id linked to mapping to total_mapping_id
formula field is an string that are the level1_category_id that has to be add or substracted.
I want to do a dax that if total_mapping_id is null the PL_Amount, if not I want to use the formula from the string...but I could not have a good result, any idea how to do that? Everything is linke with a backoffice where the end user creates totals and is added to mapping table
Thanks for your help I'm totally frustraded
Hi quickbi
You can maintain a disconnected table that has separate rows for each category id in each line item
And use this measure to return the value for each P&L line
line value = CALCULATE( SUM(RevenueTable[Value]), TREATAS( SELECTCOLUMNS( FILTER( RevenueLines, RevenueLines[Operation] = "add" ), "Category ID", RevenueLines[Category ID] ), RevenueTable[Category ID] ) ) - CALCULATE( SUM(RevenueTable[Value]), TREATAS( SELECTCOLUMNS( FILTER( RevenueLines, RevenueLines[Operation] = "subtract" ), "Category ID", RevenueLines[Category ID] ), RevenueTable[Category ID] ) )The other approach is to create a measure for each line and return the values using a condition.
SWITCH ( SELECTEDVALUE ( 'table'[name] ), "Total Gross Profit", [Total GP Measure], "Total EBIT", [Total EBIT Measure] )hi quickbi
That’s not how the table should be structured. In my example, each Category ID has its own row — they aren’t combined into a single row for each revenue line. There should also be an indicator showing whether the Category ID is an addition or a deduction. In the Query Editor, you can start by splitting the Category IDs. After that, you will need to transform the data so that each Category ID appears in its own row. Below is a sample custom column to split the category individually.
Text.Split([category id column], ",")This will create a column with each row containing a list of values. Expand them into new rows (there will be an expand icon next to the column name). Remove trailing and preceding spaces by right click the colum and selecting Trim or Clean.
9 Replies
- danextian
Super User
Hi quickbi
You can maintain a disconnected table that has separate rows for each category id in each line item
And use this measure to return the value for each P&L line
line value = CALCULATE( SUM(RevenueTable[Value]), TREATAS( SELECTCOLUMNS( FILTER( RevenueLines, RevenueLines[Operation] = "add" ), "Category ID", RevenueLines[Category ID] ), RevenueTable[Category ID] ) ) - CALCULATE( SUM(RevenueTable[Value]), TREATAS( SELECTCOLUMNS( FILTER( RevenueLines, RevenueLines[Operation] = "subtract" ), "Category ID", RevenueLines[Category ID] ), RevenueTable[Category ID] ) )The other approach is to create a measure for each line and return the values using a condition.
SWITCH ( SELECTEDVALUE ( 'table'[name] ), "Total Gross Profit", [Total GP Measure], "Total EBIT", [Total EBIT Measure] )- quickbi
Helper II
Hi danextian
I modified the SQL and I created a string with the values that has to be included in a calculated condition using "in"declaring formula field as a _Formula (variable) an including in a calculate formula
CALCULATE(
[PL_Amount],
REMOVEFILTERS('Mapping'),
'Mapping'[cashflowcategory] IN { _Formula }
What do you think?- danextian
Super User
hi quickbi
That’s not how the table should be structured. In my example, each Category ID has its own row — they aren’t combined into a single row for each revenue line. There should also be an indicator showing whether the Category ID is an addition or a deduction. In the Query Editor, you can start by splitting the Category IDs. After that, you will need to transform the data so that each Category ID appears in its own row. Below is a sample custom column to split the category individually.
Text.Split([category id column], ",")This will create a column with each row containing a list of values. Expand them into new rows (there will be an expand icon next to the column name). Remove trailing and preceding spaces by right click the colum and selecting Trim or Clean.
- lbendlin
Super User
You cannot use EVALUATE like this in Power BI DAX, unfortunately. Your "formula" will need to be hardcoded.
- Ritaf1983
Super User
Hi quickbi
You cannot directly reference the formulas as functions in Power BI, because there is no data type that is treated as a "function" or "formula."
To achieve the manipulations you're aiming for, the business logic must be explicitly constructed inside Power BI.You can manage this using techniques such as:
-
Variables inside a measure, to control different logic paths.
-
Field Parameters, if you want to dynamically select fields or categories.
-
Dynamic Measures, using SWITCH or TREATAS, depending on your model structure.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
-