I need to write DAX expression to create a new column in the selected table:
Logic: if price is above average price + 15% then group “+15%”, below 15% then “-15%”, above 25% then group “-25%”, below 25% then “-15%”
In progress:
average_price_plus_minus = if([Price, EUR] / [Average price, EUR] > 1.15," +15%", if([Price, EUR])/[Average price, EUR]< 0.85,"-15%")
Related
I am trying to get a rolling 3/6/12 month average of revenue by month using DAX in a SSAS Tabular model. There is a date table in my model and I have created inactive links between my fact table and my date table for each date in the fact (Date of Service, Invoice Date, etc.). I have created a measure that uses USERELATIONSHIP to activate the specific link I need.
Revenue by DOS:=
CALCULATE( [Total Gross Revenue],
USERELATIONSHIP(D_DATE[W_DT_ID],Fact_Charge[W_SERVICE_DT_ID])
)
Here is the code I am using to create the rolling average, which I copied from a SQLBI video on the same subject:
Net Revenue R3M:=
VAR NumOfMonths = 3
VAR LastSelectedDate = MAX(D_DATE[Calendar_Date])
VAR Period =
DATESINPERIOD( D_DATE[Calendar_Date], LastSelectedDate, -NumOfMonths, MONTH)
VAR Result =
CALCULATE(
AVERAGEX(
VALUES(D_DATE[Month Year]),
[Revenue by DOS]
),
Period
)
Return
Result
For some reason when I deploy the model and try to use it in Power BI, it runs this rolling average at the year level, but not the month. For instance, the Power BI matrix visual will show the year 2021 and will have a value that is equal to the average of the last 3 months of 2021, but the individual months show the same value that is contained in the Revenue by DOS measure itself.
Snip From Power BI
The goal is to have each individual month in the Revenue R3M column to be the 3 month average of the Revenue by DOS column.
I am calculating total revenue over the years.
There are two tables calendar and sales. I have calculated total revenue using DAX now I want to display total revenue in each year.
The month field is not getting filtered for the Revenue column, I have attached a snip for reference.
Total revenue(DAX)= total revenue = SUMX(AW_Sales,AW_Sales[OrderQuantity] * RELATED(AW_Products_Lookup[ProductPrice]))
I am trying to calculate the Cumulative Purchases by YTD. The first step is to rank the items by Cost Amount, but when I try to rank by the [_YTD Cost] measure, the numbers I get do not make sense (skipped numbers, duplicated).
[]
I had 3 slicers: Month, Year and to select Month/YTD measures. Since with the Month calculation I have no problems, I removed the interaction with the Month/YTD slicer and I placed only YTD measures on the table:
Total Purchase Cost = SUM ( Purchases[Amount] )
_YTD Cost = TOTALYTD([Total Purchase Cost], 'dim-calendar'[Date])
_RANK YTD = RANKX(ALLSELECTED(Purchases), [_YTD Cost])
Notes:
I pulled the item from the Item table
The Purchase table is linked to the Date table by Purchase Date
Not 100 % sure on your data model, but try changing your RANKX(ALLSELECTED(***) to reference the Item-column. Like this:
RANKX(ALLSELECTED('Item'[Item]), [_YTD Cost])
I have facts tables with sales
I would like to create measure that counts number of products where sum of sales for particular product is higher than 2% of total sales.
For example:
1. sum of sales for 'ProductKey' 310 is 5000.
2. sum of sales for 'ProductKey' 346 is 2000.
3. 2% of sum of total sales is 3000.
Product 310 would be included in count product 346 wouldn't be included in count.
How would I write such measure?
I've tried to created something like this:
Big Sales =
var SalesTotal = CALCULATE(SUM(fact_InternetSales[SalesAmount]))
var twoperceSalesAmount =
CALCULATE (SUM(fact_InternetSales[SalesAmount]), ALL( fact_InternetSales )) * 0.02
return
CALCULATE (COUNT(fact_InternetSales[ProductKey]),
FILTER (fact_InternetSales, SalesTotal - twoperceSalesAmount > 0))
Thansk
Kind regards,
Robert
You were almost there.
The pseudoalgorithm is:
1. Calculate threshold
2. Consider only product with sales above threshold
3. Count number of products
Big Sales:=
var _threshold = CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02
var _productlist =
FILTER(ADDCOLUMNS(
SUMMARIZE(
fact_InternetSales,
fact_InternetSales[ProductKey),
"productsales",CALCULATE(SUM(fact_InternetSales[SalesAmount]))),
[productsales]>_threshold)
RETURN
Countrows(_productlist)
If it is very slow web can optimize it.
Also solution with SUMX works:
Big Sales SUMX =
SUMX(VALUES(fact_InternetSales[ProductKey]),
IF(CALCULATE(SUM(fact_InternetSales[SalesAmount]))>
CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02,1))
I have two columns of data, FTE REGION TOTAL AMOUNT and FTE REGION TOTAL FTE.
I want to calculate the cost per FTE by Region (by dividing the sum of the ActualExpensebyRegion column by the ActualFTEbyRegion column).
My divide formula below is not working
costperfte = DIVIDE(fteregiontotal[AMOUNT],fteregiontotal[FTE])
I know that Power BI will calculate the sum of each column, but how do I perform a calculation using those sums and divide by region.
Expected Outcome
Region Cost per FTE
------------------------------------
EMEA 7,049
APAC 2,178
LATAM 403,380
CAM 1,190
NALA 23,797
Create this measure:
Cost Per FTE by Region :=
VAR Numerator = SUM('fteregiontotal'[Amount])
VAR Denominator = SUM('fteregiontotal'[FTE])
RETURN
CALCULATE(DIVIDE(Numerator , Denominator ))
And use it in a matrix or table with your [Region] in the "Rows" field and the measure in the "Values" field.