Using SUM & COUNTIFS against unique ID - excel

I have a dataset that exports all actions by a candidate appointment database, but as the candidate can be booked for more than one appointment all I want to check is the candidate has attended one appointment within the given month.
Currently I use the below formula:
=SUM(COUNTIFS(ActionsImport[Activity Type], "Appointment*", ActionsImport[Status/Outcome], "Attended", ActionsImport[Activity Date], ">="&AS2, ActionsImport[Activity Date], "<="&AZ2))
ActionsImport[Activity Type] - Is to look for all Appointments
ActionsImport[Status/Outcome] - Is if they have attended
ActionsImport[Activity Date] - Is the start and end date range
I also have ActionsImport[Candidate ID] that I can use as a unique identifier, but I'm not sure how I would go about creating the unique search. I have been looking into SUMPRODUCT and FREQUENCY, but without much luck.

Related

Sum from two tables with filters in DAX/Power BI

I've got two tables.
The 1st one contains SKU, client, order date, order amount.
The 2nd one contains SKU, client, promo id, promo start date, promo end date.
I need to calculate ordered amount for each client-promo-SKU.
In Excel I would have something like:
SUMIFS(
TABLE1[ORDERED],
TABLE1[CLIENT], TABLE2[CLIENT],
TABLE1[ORDER DATE], ">="&TABLE2[ORDER START DATE],
TABLE1[ORDER DATE], "<="&TABLE2[ORDER END DATE],
TABLE1[SKU], TABLE2[SKU]
)
Table 1
Table 2
Excel formula. Cells K2 and K3
I've already figured out how to filter the first table by date (the connection between ORDERS and PromoLib tables is SKU, many to many):
ordered = CALCULATE(
SUM(ORDERS[order qty]),
KEEPFILTERS(DATESBETWEEN(ORDERS[Document Date], PromoLib[Order Start],
PromoLib[Order End])),
)
How can I add filters to this DAX formula so it will filter the ORDERS table by client?
The best practice would be to have a Clients dimension table, a Dates dimension table, an Orders fact table and a PromoLib fact table. Then the measures would be much simpler. That being said, here is the syntax for the CALCULATE function:
CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])
You can add as many filter arguments as needed, so you could add another argument for a client filter like this:
FILTER (Orders, Orders[Client] = PromoLib[Client])

Calculate number of records that satisfy the condition of 5 different Dates, in Excel, from Data Source

I have very awkward database(4mln rows), structured like this:
id, start , suspension, renewal , stop , delete , category
1, 01-01-2019, 01-02-2019, 01-03-2019, 01-04-2019, 02-04-2019, A
2, 01-01-2019, , , 01-04-2019, 02-04-2019, B
I can create nice Pivot Table, with date of lets say "suspension" as Column, number of unique id's as Values, Category as filter, and then see how many Items were suspended each day.
But I need to see as well, how many Items were active each day - that means Started, not Stopped or Deleted, and Renewed if Suspended.
Unfortunately it is not as simple as "substract number of deleted from started each day".
So when I filter category A in pivot table, Excel checks every record if category == "A", right?
Can I do something similar, to check if start <= date & (stop or delete >= date) & if(suspension <= date){renewal <= date} for each row, for each date?
Try using a calculated field. U can put the formula almost directly in there. May need some tweaking.
https://support.office.com/en-us/article/calculate-values-in-a-pivottable-11f41417-da80-435c-a5c6-b0185e59da77

Showing Last Sold Date In a Netsuite ITEM Saved Search

I've created a search that shows current inventory on hand, their purchase price, and a formula that multiplies the two to have current value.
In the results field I want to have a column that shows the last time an item was on a sales order. but i am coming up short. Is there a way to do this?
Filter Criteria
Results Criteria
Criteria -
Inactive - FALS
Type - Inventory Item
Transaction Field: Type - Sales Order
Available - Is greater than 0
RESULTS -
Name - (Summary Type Group)
Description - (Summary Type Group)
Available - (Summary Type Count)
Transaction Fields - Date (Summary Type Maximum)
Did you create the saved search from the Item Record or Transaction Record?
If you created it from the Transaction Record then you will want to make sure to use the Date Field and Summary Type (Results tab) as Maximum.
Field = Date
Summary Type = Maximum
If you created the saved search from the Item Record you will need to use the Transaction Fields... table join to bring in the Transaction Date field.

Measure for sum of open positions in accounting (two date columns in source)

I would like to calculate the sum of open positions in a receivables account. The entries in the accounting system provide three relevant columns in the source table to that end:
booking date
due (=pay) date
amount due
I would like to have a measure that I can use for a graph, showing the total of all open positions on each day.
An open position is an amount booked with a booking date before "today" and with a due date after "today".
I tried the following approach in my Power Pivot model (with three calendar tables):
booking date related to "calendar table 1"
due date related to "calendar table 2"
Date columns of "calendar table 1" and "calendar table 2" related to a third "calendar table main"
For that formula I am getting an error message:
Hm, not sufficiently proficient in PowerPivot to solve this problem.
SumAmt:=
SUM( Source_Table[Amount] )
OpenPositions:=
CALCULATE(
[SumAmt]
;FILTER(
VALUES( Source_Table[Booking_Date] )
;Source_Table[Booking_Date] < MAX( Calendar_Main[Calendar_Date] )
)
;FILTER(
VALUES( Source_Table[Due_Date] )
;Source_Table[Due_Date] > MAX( Calendar_Main[Calendar_Date] )
)
)
Your error is pretty self-explanatory. If you use a direct column reference in CALCULATE() you can only reference a single column. You are referencing two, Calendar_Main[Calendar_Date] and either Source_Data[Booking_Date] or Source_Data[Due_Date]. This is simply not allowed, so it throws the error.
The workaround is simply to wrap complex filtering logic in table expressions and use those as arguments to CALCULATE(). Pretty much, unless you are hard-coding a literal predicate for a single column, you should be using some sort of table expression, like FILTER(), as your arguments to CALCULATE().
What we do is call FILTER() twice to check the dates. We use MAX()s because we cannot perform comparisons between column references, we need to perform inequality comparisons between scalars.
Since we're FILTER()ing over Source_Data[Booking_Date] and Source_Data[Due_Date], the references to these are evaluated in row context and refer to the value of the current row in FILTER()'s iteration. The reference to Calendar_Main[Calendar_Date] is just a column reference, so we wrap it in MAX() to get a scalar value for our inequality. The MAX() refers to the current filter context coming in from the pivot table, which would be the current row label or column label.
If you aggregate to the month level, this will give you essentially the closing balance, since we're using MAX()s. At the month level the value will be identical to that on the last date of the month.
Finally, with the inequalities you've set up, you're ignoring anything opened on the current day or due on the current day. I'd expect you want [Booking_Date] <= [Calendar_Date] and [Due_Date] > [Calendar_Date].

PowerPivot - relating data by date range

Does anyone know what DAX function I should use to display information from one table in another table.
I've got 2 tables in my data model:
Tasks
- Task ID
- Task Name
- Start Date
- End Date
Fiscal Periods
- ID
- Period Name
- Start Date
- End Date
What I'm trying to do is for each Task, add a calculated column the is populated with the corresponding Fiscal Period ID. I'm trying to add a filter or calculation that specifies:
- if the task start date is between Fiscal Start Date and Fiscal End Date, return the fiscal period id.
Anyone have any ideas?
Thanks,
Ro
This might help:
In case Fiscal Period ID is a number:
=CALCULATE(MAX(Periods[ID]),FILTER(Periods,Periods[Start Date]<=Tasks[Start Date] && Periods[End Date]>=Tasks[Start Date]))
In case Fiscal Period ID is not a number:
Put Start Date to calculated column first, say 'Period Start Date'
=CALCULATE(MAX(Periods[Start Date]),FILTER(Periods,Periods[Start Date]<=Tasks[Start Date] && Periods[End Date]>=Tasks[Start Date]))
and then use LOOKUPVALUE for ID
=LOOKUPVALUE(Periods[ID],Periods[Start Date],Tasks[Period Start Date])

Resources