In my Google spreadsheet document, I have a table of bills with a column J for dates and a column P for amounts. I would like to build another table that sums these bills by year (one row = one year). The P column has contents like "3245,20 EUR".
Here is the formula I tried (in this example, S5 should be the sum and R5 a numeric value of a specific year) :
S5=SUMIF(YEAR($J$5:$J), R5, VALUE(REGEXEXTRACT($P$5:$P, "^([0-9]+,[0-9]{2}) EUR$")))
This doesn't work. Any solution ? Thank you.
You can use the following formula
=SUM(QUERY({A2:A,ArrayFormula(VALUE(REGEXEXTRACT(SUBSTITUTE(B2:B,",","."), "^([0-9]+\.[0-9]{2}) EUR$")))},
"select Col2 where year(Col1)="&A1&""))
The reason we have to use SUBSTITUTE is because it looks like the price values come from a different locale.
(Please adjust ranges to your needs)
Functions used:
QUERY
ArrayFormula
VALUE
REGEXEXTRACT
SUBSTITUTE
SUM
Related
I am super new to power bi and Dax and i need to create a calculated column in which i have the total sales for each country respectively.
Here is a screenshot with an oversimplified scenario but if i can do it for this data i can do it in my actual project since the concept is the same.
The column TotalSalesPerCountry is the calculated column.
And here is what the column should look like if it worked. (Colors are just for visual representation)
Basically everywhere you see the same country you should see the same TotalSalesPerCountry values which are calculated by sum-ing the Sales for those countries over the years.
Another DAX function:
= CALCULATE(SUM(CountrySales[Sales]), FILTER(CountrySales, CountrySales[Country] = EARLIER (CountrySales[Country])))
This is simple to do in DAX. Add the column:
TotalSalesPerCountry =
var curCountry = yourTable[Country]
return CALCULATE(SUM(Sales), FILTER(yourTable, curCountry = yourTable[Country]))
Explanation:
For each row in the table, get the country. Filter yourTable on the curCountry and SUM this together).
I have a table with first row as header and first column as week number, I need to sum all the data on every week that meets the criteria depending on the header name.
This formula only filter by header and week, but I can't summarize the data, I would like that the formula is "dynamic" because the header name section can change:
=QUERY(TRANSPOSE(A1:AA23),"SELECT * WHERE Col1 = 'M.O.'",1)
This is an example spreadsheet, at the end is the desired result:
LINK TO EXAMPLE SHEET
use:
=INDEX(QUERY(SPLIT(FLATTEN(IF(D2:24="",,D1:1&"×"&A2:A24&"×"&D2:24)), "×"),
"select Col1,sum(Col3)
where Col1 matches 'INDIRECTO|M.O.'
group by Col1
pivot Col2"))
Did anyone know how to convert RunningCount into Power bi Dax ?
I test on RunningTotal, Rankx but seems not working.
The [year] is just a text column not in Datetime format.
I still new on this and not sure if my explain is good enough or not. Sorry for any inconvenient cause.
I try to create measure/ calculation column in power bi from the formula below.
I need the count by Year, break by column like product, customer, rate and category.
Before I get into my solution, there are a few assumptions I had to make:
The "Year" column is supposed to be years, and not five digit numbers. So in my data I dropped the second "2" in each (i.e. "20213" -> "2013").
You may have another column in your data to break ties, but given the data you provided, there is no way to rank the first and third lines (they both have product ABC and year 2003).
Given those assumptions, here is my solution...
First, here is what my data looks like. I added an ID column so that we can see every row, even duplicates.
From there, you can simply add a new column with the following formula.
Running Count =
COUNTROWS(
FILTER(
'Data',
[ProductName] = EARLIER([ProductName]) &&
[Customer] = EARLIER([Customer]) &&
[Seller] = EARLIER([Seller]) &&
[Year] <= EARLIER([Year])
)
)
The EARLIER function is being used to specify a ProductName, Customer, etc. from the row of the table to be used in the filtering of the data. Once we have the data filtered, we can simple count the number of rows.
The final result looks like this. As noted in my second assumption, there is no way to break ties, so my numbers are slightly off from what you have in your screenshot
I need to sum the values of stock on hand at a selected date, these values need to roll up into 2 or more categories.
The following measure gives me the on hand value at the lowest level item, but when it rolls up to the sub Category or Category level, it sums all the values and not the LASTNONBLANK per child item.
On Hand = CALCULATE(SUMX(Stock,[SOH]),FILTER('Calendar',[Date] <= LASTNONBLANK('Calendar'[Date],SUM(Stock[SOH]))))
My data set is similar to this:
Now to get the last SOH value where date <= 10 Dec 2017 works with my measure, with results like this.
As soon as I need to roll the aggregation up by removing the Size column the sum does not work as expected anymore.
This is what I need it to look like:
Similar to that I need the Category level to sum all the LASTNONBLANK values of the lowest level items, like this:
Any help would be appreciated.
I normally prefer to use measures rather than calculated columns in DAX but, because the relevant SOH values rely on a comparison the lowest level, this is a situation where I would add a calculated column.
Latest SOH:=
if(
CALCULATE(
LASTDATE('Stock'[Date]),
ALLEXCEPT('Stock',Stock[Category],Stock[Sub Category],Stock[Size])
)=Stock[Date],
'Stock'[SOH],
BLANK()
)
Starting from the middle and working out:-
ALLEXCEPT(...) is looking at all entries in the table that have the same value for Category, Sub Category and Size
CALCULATE(...) is then finding each of the last dates where there is a match
='Stock'[Date] is then checking to see if this row is the row with the highest date it can find with this Category/Subcategory/Size combination
If the values do match, then bring through the value of SOH, otherwise leave the cell blank.
Here's what it looks like in PowerPivot:
I wasn't quite sure what you wanted your dates to show. I've just added a measure that takes the LASTDATE of the date column:
And
I hope this helps!
Try to group by columns Category and Subcategory using sumx inside
GROUPBY (
Category,
SubCategory,
“SOH”, SUMX(expression)
I have a list in SharePoint Office 365 with a number of columns to register and track claims.
One of the columns is a calculated one - to catch the duration of claims processing.
I would like to calculate it as a difference between dates and shown in days.
To do it I want to use 3 pieces of information:
Column [RegistrationDate]
Date of new registered claim.
Column [EndDate]
Finalization of the claim.
[Today]
Sytem date for now.
The logic to be done by the formula should be:
IF [EndDate] is empty THEN:
[Today]-[RegistrationDate]
OTHERWISE
[EndDate]-[RegistrationDate]
Question: What formula will achieve my desired output?
Calculated columns cannot use the [Today] dynamic variable. (Validation formulas can.) Calculated Columns are only updated when they are edited, not each time they are viewed.
If you could use [Today], it would look like this:
=IF( ISBLANK( [EndDate] ), [Today]-[RegistrationDate], [EndDate]-[RegistrationDate] )
But... you cannot use [Today] in a calculated column...