I have a situation in which I have a single excel file with one sheet, I am loading this single sheet (Sales) as a Power BI table.
I have two major dimension columns - Model and Product. I have a single numerical column called SalesAmount.
In all there are just 3 source columns in my Sales table.
One Model can have many Products, hence a 1:M relationship, but in the same (Sales) table.
I am using a Power BI matrix, as shown.
I have the following:
1)
Measure called [Sum of SalesAmount]: a simple sum of the SamesAmount column
2)
A Calculated Column called [ModelSalesAmount] in the Sales table:
ModelSalesAmount = CALCULATE(
SUM(Sales[SalesAmount]),
ALLEXCEPT(Sales,Sales[Model])
)
A Calculated Column called [ProductOnModel] in the Sales table:
ProductOnModel = Sales[SalesAmount]/Sales[ModelSalesAmount]
I have the matrix visual as shown.
The aggregated value for the ModelSalesAmount is incorrect.
HL Fountain Frame is a Model, and there are 8 products under this Model.
The Calculated column Sales[ModelSalesAmount] with a SUM aggregation in the matrix, works correctly at the product level (3,365,069.274), but not at the Model level. The Model level aggregation 26,920,554.19 is incorrect. I would want 3,365,069.274 at the Model level, NOT 26,920,554.19.
Interestingly, the Calculated Column Sales[ProductOnModel] with a SUM aggregation in the matrix, while using the Sales[ModelSalesAmount] Calculated Column in the denominator works correctly, both at the individual product level, as well as at the Model level!
What should I do to remove the undesired value 26,920,554.19, and make it 3,365,069.274 ?
I tried this below, but not working:
ModelSalesAmount_CC = IF (
HASONEVALUE(Sales[Product]) = TRUE,
CALCULATE(
SUM(Sales[SalesAmount]),
ALLEXCEPT(Sales,Sales[Model])
),
...........
)
Any suggestion please?
Change the Calculated Column [ModelSalesAmount] to a measure, I get the right output. Thanks Alexis.
Related
I am super new to power bi and Dax and i need to create a calculated column in which i have the total sales for each country respectively.
Here is a screenshot with an oversimplified scenario but if i can do it for this data i can do it in my actual project since the concept is the same.
The column TotalSalesPerCountry is the calculated column.
And here is what the column should look like if it worked. (Colors are just for visual representation)
Basically everywhere you see the same country you should see the same TotalSalesPerCountry values which are calculated by sum-ing the Sales for those countries over the years.
Another DAX function:
= CALCULATE(SUM(CountrySales[Sales]), FILTER(CountrySales, CountrySales[Country] = EARLIER (CountrySales[Country])))
This is simple to do in DAX. Add the column:
TotalSalesPerCountry =
var curCountry = yourTable[Country]
return CALCULATE(SUM(Sales), FILTER(yourTable, curCountry = yourTable[Country]))
Explanation:
For each row in the table, get the country. Filter yourTable on the curCountry and SUM this together).
im struggling with the following problem. I have categorical variables and and Amount column. What I want to do is, to write a dax measure which calculates the moving/rolling Sum, like you see in the third column "Dax Measure". Did not find any inhouse Dax function for that.
moving sum
EDIT:
Result Table with Dax Measure
Source Table
This will work if the category is always sorted ASC.
Dax measure =
VAR _currentRank = RANKX(ALL('Table'[Category]),CALCULATE(MIN('Table'[Category])),,ASC)
RETURN
CALCULATE(
CALCULATE(SUM('Table'[Amount]),TOPN(_currentRank,VALUES('Table'[Category]),MIN([Category]))),
ALL('Table'[Category])
)
Using RANKX to define the other and aggregating for all the item before it.
I have a base table 'Orders' with a column OrderNo, this column is being used in a visual.
I have another table 'Operations' with columns: OrderNo, OperationNo, TimeTaken (this is just a numeric column). This table is related to base table with OrderNo. Please note that one OrderNo can have multiple OperationNo.
I want to add a column to my visual 'TimeRemaining', which takes all OperationNo (from Operations table) for an OrderNo and sums the TimeTaken column.
How can I achieve this?
Power bi groups the data in a visual automatically.
if they are linked you can make a calculated column in Orders
TimeRemaining =
SUM ( OperationNo[TimeTaken] )
if you want a it in the Operations specifically then:
TimeRemaining =
CALCULATE (
SUM ( Operations[TimeTaken] ),
ALLEXCEPT ( Operations, Operations[OrderNo] )
)
NOTE.
the first is for a calculated column in Orders table
the second one is for the Operations table.
Power BI newbie here and I'm trying to figure how to craft my DAX to manipulate my measure values based on certain criteria in the other two tables.
Currently I have 2 separate tables which are joined by a One to Many relationship and a separate Measures table. (Total Sales Price is computed as sum of Sales Price)
My aim is to create a new measure where Total Sales Price is multiplied by 1.5x when DIM_Product_Type[Product Category] = "High".
New Measure =
CALCULATE (
SUM ( FACT_PriceDetails[Sales Price] ),
FILTER ( DIM_Product_Type, DIM_Product_Type[Product Category] = "High" )
) * 1.5
However this returns no values in my visual and I'm trying to discern if its a matter of the table joins or the DAX expressions.
Thank you for your time!
Your measure seems good.
It will select only those products with a Product Category of "High" and multiply them by 1.5 to give you result. i.e. Give me the sum of all "High" Product category Price details multiplied by 1.5.
What you need to check is:
Product Serial Numbers match across the two tables
Your Product Category does indeed contain the category "High"
You have entries in FACT_PriceDetails that link to a DIM_Product_Type that has a category of "High"
Check you have not set any filters that could be hijacking your results (e.g. excluding the "High" product category product type or the realated fact/s)
Option-1
You can do some Transformation in Power Query Editor to create a new column new sales price with applying conditions as stated below-
First, Merge you Dim and Fact table and bring the Product Category value to your Fact table as below-
You have Product Category value in each row after expanding the Table after merge. Now create a custom column as shown below-
Finally, you can go to your report and create your Total Sales measure using the new column new sales price
Option-2
You can also archive the same using DAX as stated below-
First, create a Custom Column as below-
sales amount new =
if(
RELATED(dim_product_type[product category]) = "High",
fact_pricedetails[sales price] * 1.5,
fact_pricedetails[sales price]
)
Now create your Total Sales Amount measure as below-
total_sales_amount = SUM(fact_pricedetails[sales amount new])
For both above case, you will get the same output.
Here is the source data:
Columns: [Version, Unit, Customer, Quarter, Sales)
Here are the potential values:
*Note: We may have 10 different versions and 20+ different quarter year combinations.
Here is the output matrix in Power BI:
*Users can select a Version and two quarters to compare.
Here are the Power BI Visualizations and Fields:
I would like to create a measure to calculate the difference between Version 1 and 2 like this (Columns E and H):
I'm able to create a new table with columns of sales for Version 1,2,3 then calculate the difference. The problem is I need the version and quarter to be dynamic. Any ideas how to do this in Power BI?
You can do something like
Delta = IF (HASONEVALUE('Table'[Version]),
SUM('Table'[Sales]),
CALCULATE(sum('Table'[Sales]), LASTNONBLANK('Table'[Version], sum('Table'[Sales])))
- CALCULATE(sum('Table'[Sales]), FIRSTNONBLANK('Table'[Version], sum('Table'[Sales])))
)
So whenever you have two versions in the filter context, it subtracts the first from the last, and whenever only one version is in the filter context, it passes the value through.
To add to this.
How to fix the duplicated columns in each of the subcategories.
I used the below DAX but somehow it's duplicated the calculated column "Delta TMCGP%" in all the subcategories. when i just want to show it at the end of the matrix table (Power BI)
Delta TMCGP% = CALCULATE([TMCGP%], FILTER( ALL(BC_Dashboard_V4_Standard[TYPE (groups)]), BC_Dashboard_V4_Standard[TYPE (groups)]="4_CWV") ) - CALCULATE([TMCGP%], FILTER( ALL(BC_Dashboard_V4_Standard[TYPE (groups)]), BC_Dashboard_V4_Standard[TYPE (groups)]="5_POR" ) )