Power BI substruct from salary for each person and month - powerbi

My Table
Hi ,
I have this table in power bi . Each person has lines for each month passes . 5 months equals to 5 appearances in the list. for each line and the number of days ( between START AND END column) i want to substract from the MONEY column the MONEY PER MONTH COLUMN and keep the differnce .After this differnce to be substracted again with the column MONEY PER MONTH from this row until i have 0 . The only catch is that i want if the difference( happens a lot of times at month 5 out of 5 ) if the MONEY PER MONTH column is less than 20 , i want it to be 20 and the before result 240. After the last month when a new name record comes the money again to be 1040
BASICALLY I WANT TO FORM THE RED LINED COLUMN IN IMAGE BELOW COLUMN THAT I WANT TO ADD

Related

Graph a daily amount in between two dates

The source table has a table with a single amount and a revenue start and revenue end date. I need to graph the amount over the period by day in PowerBI.
For example:
Looking at the second row the total amount is 730 but I need to calculate a daily rate and display this each day for the revenue period. So if I had a bar chart for this row I would need to show it as 16 April has 34.76, 17 April has 34.76 and so on until 6 May which is the revenue end date. I've tried using between dates but cant seem to get it working.
You can use Power BI's CALENDAR() function to create a table of dates ranging from the minimum revenue start date to the maximum revenue end date.
Dates = CALENDAR(MIN(BookFees[Revenue Start Date]),MAX(BookFees[Revenue End Date]))
Then you can create a calculated column in the Dates table for the daily revenue.
Daily Revenue = Calculate(SUM(BookFees[RevenueDayAmount]),FILTER(BookFees,BookFees[Revenue Start Date]<=Dates[Date] && BookFees[Revenue End Date]>= Dates[Date]))
Here is the resulting bar chart:

Power BI - setup day 1 based on value in another column

I have table in Power BI with following columns: Country, Date and event. I would like to add measure or new column if needed with 'Start Day'. 'Start Day' assignes value '1' at the first day that value greater than 0 apears in column 'event' and starts counting days from this date. In example below for country UK value 1 in column 'event' apears on 19/03/2020 and in column 'Start Day' value 1 is assigned. Next date 20/03/2020 has value 2 assigned and so on. What is the best way to do this in Power BI?
Robert
You need to create an extra column as this is static data.
You can do this by first getting the start date of that country and then take the datediff between the dates.
In the CALCULATE function, I get all rows where the country is equal and where the event = 0. From those rows, I get the max date (firstD). This was the most important step as we can now use the DATEDIFF to calculate the days.
I used the max function once more because you want to have 0 in the rows before the startdate.
Start Day =
var country = events[Country]
var firstD = CALCULATE(MAX(events[Date]);FILTER(events;events[Country] = country && events[event]=0))
return max(DATEDIFF(firstD;events[Date];DAY);0)

Power Bi DAX: Divide Value and set it for each week

I have a target value of 20 for January but it is 20 for the month, i need to show this over each week. I have to divide the target by 4 if there are 4 weeks in a month and by 5 if there are 5 weeks in a month. It is as simple as that, i am using a line and clustered column chart to display my data, i need the target spread out into each week of the month. I also need another field to do this but im sure i can replicate your formula and make it applicable.
I have added a WeeksinMonth column that counts how many weeks are in a particular month e.g January has 5 weeks and February has 4 weeks. I need an IF statement that will divide the target and value by how many weeks in a month. e.g if month has 5 weeks then divide target and value by 5, if month has 4 weeks divide target and value by 4.
I have a calendar table with week values which i can used to put the divided target into and also the desired output i made in excel (See attached).
How will i go about this?
Desired Output
Calendar Table
enter code hereYou can create an extra column in your calendar table:
WeekMax =
var stOfMonth = Weeks[Start of Week].[Month]
var stOfYear = Weeks[Start of Week].[year]
return CALCULATE(max(Weeks[Weekinmonth]);FILTER(Weeks;Weeks[Start of Week].[Month] = stOfMonth && Weeks[Start of Week].[Year] = stOfYear))
Make sure you have a relation in your model between calendar and target date. Now you can use this number for that week/date to divide by.
You can now add an extra column in your target table:
WeeklyTarget = Targets[Target]/Related(Calendar[WeekMax])

DAX Measure or Calculated Column from Slicer Value

I have a table with customers' SSN, account number, purchase date, and max purchase date (the most recent purchase date for SSN, across all the accounts). Customers can have multiple accounts. I know how to create a measure the calculate the distinct count of all the accounts that haven't been active since a certain date (6 months, 18 month, 24 months)..
I would like to create a measure or a calculated column to give me the following information.
when users select the date from the slicer (say 6 months) the chart shows the count of the accounts that have not made a purchase in 6 months, the users also want to have a drop down slicer("Yes", "No") to indicate if the SSN had activities under other accounts. i.e. if the max purchase date is greater than the value from the date slicer.
the table structure looks like this:
SSN AccountNumber LastPurchaseDate MaxPurchaseDate
123-45-5678 9876 8/2/2018 9/4/2019
123-45-5678 6398 9/4/2019 9/4/2019
135-65-4321 2233 6/6/2019 6/6/2019
Best way here would be if you add a custom column with the time difference (in the query designer):
= [MaxPurchaseDate] - [LastPurchaseDate]
Now you have something like this:
SSN AccountNumber LastPurchaseDate MaxPurchaseDate DateDiffDays
123-45-5678 9876 9/2/2018 9/4/2019 2
123-45-5678 6398 9/4/2019 9/4/2019 0
135-65-4321 2233 6/12/2019 6/6/2019 6
You can add another column which acts as filter for your 6 months, 18 month, 24 months (convert the DateDiffDays into months).
The following measure counts the accounts:
=Distinctcount('YourTable'[AccountNumber])
If you filter now by your 6 months, 18 month, 24 months column the measure gets after every filtering calculated again and you get your result.

Print Specific Rows and Columns in Pandas

I am having trouble printing certain values within my CSV.
I have a file that has 9 columns
Record_id Month Day Year Location_id Animal_id Sex Length Weight
and over 1000 rows.
I want to print Month , Day , and Year columns when the year is equivalent to 2002.
Because I have a lot of data I decided to only work with the first 5 rows where year is equal to 2002.
This is my code:
data.df.iloc[0:5, 1:4]
With this I can print the first 5 rows and the 3 columns I desire. However I can't figure out how to filter the year to be 2002
you can start by getting all the rows where year equal to 2002
with
filtered_data = df[df["Year"]==2002]
then you can apply your code to get only the first five rows and the three selected columns with
filtered_data.iloc[0:5, 1:4]