calculating length of stay with transfer dates in Power BI - powerbi

I am having a hard time figuring out how to calculate what I need in Power BI. The data I am looking at involves the length of stay in various programs. Some people transfer between programs and others do not. The way the transfer data is stored, I was able to extract it in the following format from SQL. The first 4 columns are from one table which is linked to a table with transfer data (last 3 columns). See below for sample data going in to Power BI.
I need to calculate the length of stay for each person in each program, taking into account the transfer data. See below for the desired output.
If the person does not have a transfer, then the length of stay is (end date) - (start date). If the end date is null, then it is calculated based on the last day of the month (in this example, 7/31/2020).
If there are transfer/s, we need to calculate the length of stay in each program.
For person 234, they were in Program A from 5/15/2020 to 6/1/2020 when they transferred to B. Person 234 was in Program B from 6/1/2020 (transfer date from A to B) until 6/15/2020 (transfer date B to C). Then Person 234 was in Program C 6/15/2020 until 7/1/2020 (end date).
Please let me know if you have any ideas of how to get this calculation. I can use Power BI which will be my output, or I could edit the SQL query. Thank you for your help; I hope this post is clear enough!

Related

Using multiple IF/AND statements to look at a query table and display a Yes/No result

I'm attempting to write a formula for excel that will look at 3 different columns of data in a query table that I'm pulling from my teams sharepoint site. I'm trying to have a Yes/No result given.
The formula I've written so far is
=IF(AND(ISTEXT(Governance_Master_List__2[Is the check c]="Yes")+(AND(ISTEXT(Governance_Master_List__2[Merged Month and Year Due]="January 2023")+(AND(ISTEXT(Governance_Master_List__2[Frequency]="Weekly")))))),"Yes","No")
So, In this example I want the formula to look at [Is the check c] for a "Yes", then Look at the [Merged month and year due] for January 2023, and then look at [Frequency] for "Weekly", and if all 3 of those are met to show the result of Yes onto another worksheet.
So far the formula isn't throwing an error when making it, but it only returns the No result, even when I ensure that all the Weekly, January 2023 entries are showing as Yes.
I'm very new to excel in terms of formulas and am learning as I go. I feel like, because the refernce query table i'm looking at has tons of different values (eg, the frequency has weekly, 6 monthly, monthly, quarterly etc and that there are 12 months to choose from) that the formula is stopping because its looking at and not ignoring those other options, hence the constant false result.
I've tried the following variations with no result..
=IF(AND(ISTEXT(Governance_Master_List__2[Is the check c]="Yes")(AND(ISTEXT(Governance_Master_List__2[Merged Month and Year Due]="January 2023")(AND(ISTEXT(Governance_Master_List__2[Frequency]="Weekly")))))),"Yes","No")
=IF(AND('Imported data'!C1:C200="Weekly")+(AND('Imported data'!E1:E200="January 2023")+(AND('Imported data'!H1:H200="Yes"))),"Yes","No")
=IF(AND('Imported data'!C1:C200="Weekly")(AND('Imported data'!E1:E200="January 2023")(AND('Imported data'!H1:H200="Yes"))),"Yes","No")
The output excel sheet is to show our quarterly compliance reporting, i'm simple trying to automate the process of entering the data into that report, as the teams use a sharepoint list to enter their compliance tasks.
Anyone have a suggestion on how I can get this working? Eventually it'll be used to populate a number of different yes/no report cells based on the relevant month and frequency of the check.

Power Bi how to calculate Net Present Value

i hope someone can help me.
I have several files (10 at least) connected by YEAR (just as number, not date) and CASE, and for each file I have a cash flow (i upload pbix sample file with 3 files only to simplify things)
So i Have Flow A, Flow B, Flow C, by year (not as date type) and not always Flow A has a value in a year corresponding for Flow B or C as can be seen on visuals
I created a measure for Total Flow and that works perfect.
But now, i need to calculate net present value for TOTAL FLOW and i was thinking in creating a Calculated Column with sum of Flow A, B and C, and then use XNPV...... but i get a total result for all rows in my column, I have my tables with relation to table with year and case, so i don't understand why can i just sum up 3 columns, by rows. It looks simple on excel, but not efficient if i chose that way
Creating a measure for XNPV it's not working, i get constan error (4 arguments)
I don't want to create a new excel file for getting NPV because it's to slow and i already did it and my dataset it's constantly changing (adding more CASES)
Any orientation ? How can i get in Power Bi, Net present value for Total FLow?
Thank you in advance
PBIX Sample

Power BI: Return sum of numerical data for each counterparty and its several currencies between two dates and its variation

I need your help regarding Power BI because I'm quite new with it. I'm struggling to compute and show what I want.
I have imported my table from a database.
What I want is to compute the sum of the Nominal for each Counterparty and each Currency, BUT it needs to respect the condition: start date <= date in the date table & end date > date in the date table. At the end, I want to show the result just like the last image, a dynamic table.
Moreover, after computing the sum of the nominal, I need to compute the difference between two dates and the % variation of it.
On my side, I was able to get the sum I want but the problem is I created columns for each counterparty and currency like 'AZE EUR', 'AZE USD', in the Date table.
BY doing this, I can't create a pie chart that defines the % of EUR or USD owned by AZE and HUB counterparties. So no dynamic chart.
I hope I was clear enough. If not let me know :)
Thank you in advance for all your helps.
NB: if the image can't be seen, let me know.

Power BI visualization of data with a Start and End date

THis is an example of what I think i need to do
I would like to ask some modeling advise I cannot solve myself:
I am using Power BI to visualize the time machinery is out of order.
The source is a register of equipment not functioning, with a start date and end date (note that there is no end date if the machine is not fixed yet).
I would like to show the time (hours, percentage, etc) that the machinery is out of order, filter for a specific period /date (e.g. month).
So I have 2 date columns: ‘’Start out of order’’ and ‘’Back in order’’
I do have a date table, which I usually would connect to all the date variables. However, since I am working with a Start and End date. This does not give the result I am looking for.
Any help is very much appreciated!
Kind regards,
Link to my Power BI FILE:
https://wetransfer.com/downloads/83ca3850392967d0d42a5cc71f4352c420200213160932/eb7353
Stijn
I am not sure how you would like to visualise your data, but this is what I managed to do:
create a daysdiff column with
Daysbetween = IF(ISBLANK(TF_Eventos
[End out of order]);DATEDIFF(TF_Eventos[Start out of
order];TF_Eventos[TODAY];HOUR);DATEDIFF(TF_Eventos
[Start out of order];TF_Eventos[End out of order];HOUR))
This creates your column to check difference between Dates.
Then create a separate column with your Date. In this case I copied the Start out of order date, since I thought you might wanted to be able to filter for the start dates. Then simply create a relationship between your newly created Date column and your start out of order date.
Doing so lets you create a visual with the daysbetween (in this case portrayed in hours) and your start dates. Now just simply add a slicer and you can filter on date.
Hope this helps

Count occurrences in time

Working with unemployment data, and I want to count the number of weeks that a client has received benefits during the last 52 weeks.
I have a dataset with many tables which are all connected via the client number in a fact table. In the fact table the client number occurs for every week of the year in one column, another column shows the type of benefits (if any) received in the current week. So I have a long format.
The other two relevant tables contains
A: List of client number appearing only once per client, but no information about benefits received or week number.
B: List of benefits
Tried counting the rows in my fact table while filtering so as only to do so for the specific benefit I am interested in, but I can't make it work so far.
Weeks on benefit A =
CALCULATE(DISTINCTCOUNT(FactDream[DimDreamBorger]);
DimDreamYdelse[dagpenge] = 1)
sample data
I just need a table showing how many weeks the individual client has received a specific benefit, but I keep getting a total sum of the weeks that all the clients have received the benefit.
Best would be if you add the following measure:
=CountRows(YourTable)
Put this measure into a chart visual. Then add a filter visual and put your Benefit column into the filter visual.
This way you can filter after your benefits, which you are interested, and see the result in the chart.