Correct total for measure evaluate all rows - powerbi

I am trying to use a measure to find the total impact of a price change.
Currently, I have a table with the date, region, product quantity, and revenue.
I have measures that return YTD and PY YTD for both revenue and product quantity.
AvePriceYTD = Rev YTD/ Q YTD and AvePricePYYTD = RevPYYTD/Q_PYYTD
My final measure is PE = (AvePriceYTD-AvePricePYYTD)*Q_PY
When totaling the AvePriceYTD-AvePricePYYTD is correct but when multiplying Q_PY it gives a different result to the sum of the individual PE for each region.
I know that this involves the HasOneFilter to choose the total but not sure how to evaluate each region individually and then total. It is not possible to evaluate each row as this is monthly data and there are multiple rows per region.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907
This link explains the answer, I initially didn't realize that the _table and _value were actually mean to be typed and not replaced with your own text.

Related

Getting correct Sum for total row DAX Power BI

I have:
Dim Table:
Accounts: customer granularity level.
Fact Table:
PhoneCalls. calls to customers granularity level.
I need to create and see the number of calls made to a customer up until the customer made their first deposit.
I was able to do this on the customer level but on the Total level I get a weird result:
my measure:
ACC_Calls_2_FDP =
CALCULATE(
COUNTROWS(PhoneCalls),
PhoneCalls[disposition] = "ANSWERED", -- only calls that were answered
PhoneCalls[calldate] <= MAX(Accounts[FDP_Date]), -- up until FDP date per customer
USERELATIONSHIP(Accounts[AccountNo],PhoneCalls[AccountNo]) -- make the connection active
)
the results are:
On the total level i was expecting to see 14. not 536
what is going on? what am i missing?
The data model:
Filter direction: Accounts filters PhoneCalls
Cardinality 1:*
Power BI doesn't sum up each of the row values as in Excel. Instead, for Grand total value they will still calculate it as a row itself with no filters on AccountNo on it.
In this case, the max value of FDP_Date in the whole table is taken in the measure. So for example, ACC 1 has max date of 3, ACC 3 has the max of 10. The grand total calculation will use 10 as the max value and start countrows on whichever rows with FDP_Date < 10.
To fix this is tricky as I don't have any other information than this. However, I hope this explains you well of the "bug".

Creating and Referring to a Grand total for a future calculation in Power BI

Attach is a screenshot of my tables and columns/values I have. I am very new to power BI and have searched for a solution to my problem but it all leads to a running total which I does not solve my issue.
I am trying to create a future calculated measure that needs to reference a grand total of total meals as so (grand total total meals * Fairshare %). I could create a column/measure with the grand total written into the equation but i would like to have this column dynamically change since new data will be updated on a monthly basis. The logic should be to have the new column just refer to the grand total meals (whatever value it is; 788150 in this case) multiplied with fairshare % column for each row but I can't see a way to refer to a grand total in power BI.
Let's say you have a DAX measure of:
Total Meals = [KC_Total_Meal] + [WPP_Total_Meals] + [SP_Total_meals]
That measure when it's calculated will be adjusted by the row context in your table. (I'm assuming you have a date or location to the left of your screen print.) If you are new to "context" in Power BI, try reading through this helpful reference card.
To remove the row context to get a true Grand Total, use the ALL() function within a CALCULATE() function. ALL() returns all the rows in a table ignoring any filters or row/column context that might have been applied.
Grand Total Meals = CALCULATE( [Total Meals]), ALL(Meals_Table))
Depending on the situation, you may need similar functions such as ALLEXCEPT() or EARLIER() or REMOVEFILTERS().

How do I manipulate measure values based on 2 other dimension tables

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.

How to show the total values of rows in a Matrix with number value having my columns values as percentage

I've started to manage PowerBi from a couple of weeks so i'm a little bit confused about some things.
My problem is that i need a Matrix in my dashboard with percent values but i want the total in number value because the total of a percent of row shows me always 100% and i dont know about the number i'm working
This is my Matrix with percentage values
This is how i want the total of row returns me but with the columns values ins percentage
I've tried to make a measure counting the values
COUNT(OPSRespuestas[answer])
After that turn off the total of rows and add this measure to the values in my matrix but this is what i get
This is my table after trying add a measure with the total
It returns me the total for each of the columns and not the total of all my rows.
These are the tables i'm working with
This my top header values
This is my left header values
The answer column is what i need to count
This is my relationship between this 3 tables although i have many more intermediate table aside from this 3 as you're going to see in the next picture:
My relationship tables
So finally what i need is that this matrix shows me the total of answer in percentage for each of departments and group of questions and then show me total by department but with number value
The problem you are experiencing has to do with context. Each row is seen as it own total population hence the 100% total. Each column in this row is evaluated against the total of that row to provide a percentage value.
In addition to adding a custom measure to replace the total, you could also consider computing a percentage against the grand total of all dimensions. This means that each cell gets evaluated against the the total of all rows and columns. In this ways the cell value would change compared to your first table but the row total does not evaluate to 100% anymore.
SUM ( [Value] ) / CALCULATE ( SUM ( [Value] ) ; ALL ( 'Your Table' ) )

How can I measure Number of Items with over X amount of sales?

I have a Power BI database set up as follows:
Sales[Date] is the date in which the sale took place. Sales[ProductID] is the SKU, while Sales[Units] is the number of units sold per SKU. I have also added a measure to calculate the total # of units sold. I am trying to set up a distinct count of SKUs where more than 500 SKUs were sold. I am using the following formula:
SKUsWith500Sales = CALCULATE(DISTINCTCOUNT(Sales[ProductID]),FILTER(Sales,[TotalUnits]>=500))
The output is either blank or inaccurate.
Thank you!