Objective:
Looking to generate a column measure (DYNAMIC BALANCE) which reads the first row of BALANCE, and calculate the balance from subsequent rows using AMOUNT column.
Problems encountered:
Measure should ignore the AMOUNT on the first row and only capture the BALANCE into a variable.
My first row formula grabs both values for 1/1/2021 rather than only the top most row balance value.
Date
Description
AMOUNT
BALANCE
1/1/2021
Dog Food
-20.00
980.00
1/1/2021
McDonalds
-30.00
950.00
1/5/2021
Pay Day
1000.00
1950.00
1/8/2021
Dog Food
-20.00
1930.00
1/10/2021
Medical
-1000.00
930.00
1/18/2021
McDonalds
-30.00
900.00
1/21/2021
Pay Day
1000.00
1900.00
1/31/2021
Dog Food
-50.00
1850.00
2/2/2021
McDonalds
-40.00
1810.00
You are my hero!
Here is the solution. Funny how the solution is so simple in DAX and in hindsight. M-Code would have been more complicated. DAX is dynamic to the filter which is necessary.
New Measure:
RunningTotal = FIRSTNONBLANK(bankdownload[Balance],0)+SUM(bankdownload[Amount])-FIRSTNONBLANK(bankdownload[Amount],0)
Related
I'm new to Power BI and struggling a bit with concepts. My simplified problem is this:
I have a table with time-track data (possible multiple entries per day for the same user):
datetime
timeTracked (hours)
user
2022-12-01 14:15
1.5
john
2022-12-01 16:30
0.5
john
2022-12-02 12:00
2.5
tom
I also have second table with yearly wages for each user (irregular dates, wage is applicable from that day forward):
date
user
wage
2021-01-01
john
20000
2021-06-15
tom
25000
2022-02-01
john
22000
I want to somehow calculate the cost for a dynamic period or total time, but using other filters (like client).
For example: total cost for current month - the sum of hours for each user multiplied by hourly cost (let's say yearly wage / 1500 for simplicity). The complication is that there might be multiple applicable wages in the selected period.
I'm not sure if I should create a new table, new column(s) to existing table(s), measure(s) or anything else? I don't know how to deal with this problem in Power BI, any hints, links or examples are very appreciated!
Hi everyone,
I have a sample data as shown in the screenshot above. There are 3 students with different ID : student 123, student 234, student 456. The profit column in the table is how much they earn in each trade.
Winning trade = profit > 0
Losing trade = profit < 0
Based on the definition above for the winning trade and losing trade, I want to calculate the average winning rate for all the students.
Student 123 - the winning rate is 50% (2 negative profit and 2 positive profit)
Student 234 - the winning rate is 33.3% (2 negative profit and 1 positive profit)
Student 456 - the winning rate is 100% (0 negative profit and 2 positive profit)
So, the final answer, average winning rate among all the students is:
(50% + 33.3% + 100%)/3 = 61.1%
61.1% is the final output that I want, then I will put this value into a Donut chart. I'm relatively new to DAX, any help or advise will be greatly appreciated!
Please paste text rather than images when providing sample data.
You shouldn't really add averages together like that but if that is definitely what you want, use Measure 2.
If you want a more traditional average to be calculated, use Measure 1.
Measure 1 =
VAR total = CALCULATE( COUNTROWS('Table'), ALLEXCEPT('Table','Table'[Student]))
VAR pos = CALCULATE(COUNT('Table'[Profit]), ALLEXCEPT('Table','Table'[Student]),'Table'[Profit] > 0)
RETURN pos/total
Measure 2 =
VAR students = CALCULATE(DISTINCTCOUNT('Table'[Student]), ALLEXCEPT('Table','Table'[Student]))
RETURN SUMX(VALUES('Table'[Student]), [Measure 1]/students)
I'm stuck in finding total sales of a day, I need to further find out the % of each product in a particular date.
for eg: sales of beverages for 2/17/2018
Here I am trying to find the total sales for one particular date :
I am expecting 922 in the salesperday column.
your table:
Transaction_Date
product_group
sales
SalesPerday
2/17/2018
Add-ons
$11.2
$11.2
2/17/2018
Beverages
$725.25
$725.25
2/17/2018
Food
$133.25
$133.25
2/17/2018
Merchandise
$24
$24
2/17/2018
Whole Bean/Teas
$28.95
$28.95
2/18/2018
Add-ons
$27.2
$27.2
2/18/2018
Beverages
$817.3
$817.3
2/18/2018
Food
$138
$138
2/18/2018
Merchandise
$54
$54
2/18/2018
Whole Bean/Teas
$178.18
$178.18
you need to add Calculated Columns for day with following formula:
Day = DAY('table'[Transaction_Date])
then you need SalePerDay measure
SalePerDay = CALCULATE(SUM('Table'[sales]),ALLEXCEPT('Table','Table'[Day]))
at last create following measure for calculate percentage of product category per day
%Sale = SUM('Table'[sales])/[SalePerDay]
just aware of implicit measure and don't use them.
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 am trying to do percentage of grand total. When i created the measure like
= Calculate(DistinctCount(ColumnName1),AllSelected(ColumnName2))
It gives me Overall Grand Total for that. But when i select perticular week then the Grand Total changes
For example rand Total is 23872
when i select week number from filter for week number 23 then it showing Grand Total 1232
I want to subtract the week number total from grand total i.e 1232/23872.
The 23872 this grand total should not change when apply any filter.