I am trying to build a calculaion to identify the total sum of values of product code. In tableau, we do use, {FIXED [PRODUCTCODE]: [SORT_SLICER_VALUE]}. But in power BI, I have wrote the same like below
output = CALCULATE([SORT_SLICER_VALUE],ALLEXCEPT('ProductMaster',' ProductMaster'[PRODUCTCODE]))
SORT_SLICER_VALUE = SWITCH(SELECTEDVALUE('Slicers Des'[Slicer Des]),
"Price variance/ kg Original - Actual", [Price variance/kg Original - Actual],
"Price variance/ ctn Original - Actual", [Price variance/ctn Original - Actual])
But this calculation returns the same disaggregated value in the [SORT_SLICER_VALUE] measure. As an example,
Please note that the
Related
I have below table structure:
enter image description here
here I want to put a date slicer in Power BI to filter on dates and return the count of total rows as total in the card as shown below:
enter image description here
simple, the only twist is that I want to have the total of hybrid car added at all times.
i.e.
Brands before 5/25/2020 = 4 Hybrid + 1 Electric = 5
Brands before 12/5/2020 = 4 Hybrid + 3 Electric = 7
I have found a solution, which is creating a view in my database, which jus holds the number count of hybrid car (select count(*) from table where cartype = 'hybrid') and using it to sum with filter rows in power bi - but I am looking for a solution completely in Power BI DAX query.
any measure I have tried to create in power bi is filtered by date slicer and so doesn't work.
Create these measure:
TOTALROWS = COUNT('cars'[brand])
ELECTRIC_NUM = CALCULATE([TotalRows],('cars'),'cars'[cartype]="ELECTRIC")
HYBRID_NUM = CALCULATE([TOTALROWS],ALL('cars'),'cars'[cartype]="HYBRID")
TOTALBYBUSINESSLOGIC = CALCULATE([ELECTRIC_NUM]+[HYBRID_NUM])
Now use the last measure (i.e. TOTALBYBUSINESSLOGIC) to be used in your Card to display the total, Notice the expression diffrence between ELECTRIC_NUM and HYBRID_NUM
(In HYBRID_NUM I have used ALL, All will have it bypass the Date Slicer filter) whereas ELECTRIC_NUM will only proivde sum of rows falling in the active date sliver range.
I am new in Power BI, I am trying to calculate the percentage based on the rowTotal instead of GrandTotal. for example - with my dataset in excel -
RAW Data is like -
from these raw data I want the calculation like -
Very simple problem to be solved and accept the solution if helping:
From the original table, create the Total measure:
Total = SUM(Sheet2[Compliant]) + SUM(Sheet2[Non-Compliant])
Create the Percentage measure
Percentage = SUM(Sheet2[Compliant]) / (SUM(Sheet2[Compliant]) + SUM(Sheet2[Non-Compliant]))
The outcome using table report
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" ) )
I have a challenge in power BI to calculate average YTD.
enter image description here
I am looking for make the average for month two take in consideration data from month one and so on.
Any idea how to do that in Power BI?
Thank you in advance,
Mahmoud
Not knowing why the solution by Alexis didn't work for you, I've made the assumption that you only have one table (called 'Data'), with two columns as your image showed.
Step one:
Add two new columns (if you do this in Power query or power bi doesn't matter): [Month_name] and [Month_number].
[Month_Name] = FORMAT([Date]; "MMM")
[Month_number] = MONTH([Date])
Step two:
Add a measure
YTD Avg =
var currentMonth = MAX([Month_number])
RETURN
DIVIDE(
CALCULATE
SUM(Data[Amount]);
ALL(Data[Month_Name]);
Data[Month_number] <= currentMonth
);
CALCULATE(
COUNTROWS(DATA);
ALL([Month_Name]);
Data[Month_number] <= currentMonth
);
0
)
This should generate the following table:
Hope this helps. Please don't hesitate to ask if you have further questions.