I am trying to calculate the average per thousand and can't seem to get the formula right! I am new to Power bi so any help would he appreciated:
Sample data is below:
appointment data, broken down to an average per 1000 for the NC category
*I have tried adding a new column and writing a new measure but can't seem to get the right result!
Use this Calculated Table
Result Table =
SUMMARIZE(
'Sample data',
'Sample data'[N C],
"Average", AVERAGE('Sample data'[APPOINTMENTS])
)
Related
I'm new to DAX and I'm trying to do something that would be really simple in Excel!
Using data from the same table, I'm trying to add a measure, that calculates my 'TargetCost' column where the 'NameUnit' is '1111'.
if nameunit = 1111 then sum the target cost
In excel the formula would be:
=sumif(nameunit,"1111",targetcost)
How do I write this into a measure in DAX please?
Here you go:
Measure =
CALCULATE(
SUM('Table'[targetcost]),
'Table'[nameunit] = "1111"
)
https://learn.microsoft.com/en-us/dax/calculate-function-dax
I am using power BI and I would like to create a line chart which contains values from two tables (sales history and sales prediction). So for the past 12 months, the line should reprensent the sales history and for the next 6 months, the line reprensents sales prediction. Here is what the data looks like, lets say we are in June 2021:
I know there is a way to do it in DAX but I don't know how to do it by myself. Thanks a lot in advance for your help !
You can achieve this by
Delete any relationship between Calendar and the other two tables if there is any, as we are going to use DATESBETWEEN function to calculate
Create two metric like below, you might need to adjust the column names as per your project
Sales History Amount = IF('CALENDAR'[Date] <= TODAY(), CALCULATE(SUM('Sales History'[Amount]), DATESBETWEEN('Sales History'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Sales Prediction Amount = IF('CALENDAR'[Date] >= TODAY(), CALCULATE(SUM('Sales Prediction'[Amount]), DATESBETWEEN('Sales Prediction'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Add these two metrics in the table and use the Date from the Calendar table as X axis.
Format the first metric to solid line, and dash line for the second
Calendar should be linked to your tables.
Prediction Amount =
VAR lastSalesDate = MAX('Sales History'[Date])
VAR currentPredictionAmnt =
CALCULATE(
SUM('Sales Prediction'[Amount])
,KEEPFILTERS('CALENDAR'[Date]>lastSalesDate)
)
RETURN currentPredictionAmnt + SUM()
Sales Amount =
SUM('Sales History'[Amount])
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 am trying to figure out the DAX to create a new measure in an SSAS Tabular data model. An example of what I am trying to do is more easily shown than described. My SSAS Tabular dataset produces the following table. Cols A and B are from the stores table, Col C is a measure from the Sales table, Col D is a measure from the Products table, and Col E is C/D. This all works fine. Data has been mocked up in Excel to protect the innocent, but it is working in Power BI.
What I would like to do is add a new measure which calculates the Sales/Product at the state level and have that measure show for each store in that state, as shown below
Presumably I have to iterate over all rows and calculate the total sales/state and total products sold/state and divide those 2 to get the answer, but can't work out the DAX to get there. I have tried numerous combinations of
calculate(
sumx(...),
filter(
all(...),
...
)
)
to no avail.
You should use FILTER with ALL to manipulate a context(remove current context);
MesureSumStateLevel = calculate(SUM('Table'[Amount]),
FILTER(ALL('StoreStateTab'), 'StoreStateTab'[State] =
SELECTEDVALUE('StoreStateTab'[State])))
https://dax.guide/filter/
https://dax.guide/selectedvalue/
https://dax.guide/all/
Thanks for the tip. I originally tried that and dropped it because I couldn't get it working. I revisited this morning and solved it. Here is what I did:
State Ttl =
var trxYr = convert(SELECTEDVALUE(dim_date[Year]), INTEGER) //needed because Year is stored as text in the model
var trxMo = SELECTEDVALUE(dim_Date[Short Month Name])
var trxState = SELECTEDVALUE(fact_Sales[state])
Return
CALCULATE(
SUM(fact_sales[SalesAmt])
,all(fact_sales)
,year(fact_sales[SaleDATE]) = trxYr
,dim_Date[Short Month Name] = trxMo
,dim_Stores[state] = trxState
)
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.