Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
antoinetohme
New Member

Dax function

Hey guys,

 

I have the following data table:

Stream  Start Date  Annual Salary
DevJan 1, 2022100,000
SalesMar 3, 2022120,000
SalesJuly 1, 2022100,000
PMOct 10, 2022140,000

 

I am trying to display a matrix vizualization like this, where I can calculate the total salary of each resource  by quarter based on their annual salary (i.e Salary/12 x 3 for each quarter depending on the month in the quarter they sarted):

StreamQuarter 1Quarter 2Quarter3Quarter 4
Dev    
Sales    
PM    

 

The Start Date represent the starting date of the resource with their annual salary.

I need a function to determine each quarter salary portion of that resource broken down into quarters, starting from the quarter his start date falls into.

Then using that function in a Matrix visual display the above table.

 

For example, if a resource started in June 2022 with a salary of 100K The table would display

Stream Q1  Q2        Q3    Q4

Dev      0$   8,333K  25K  25K

 

if he started in Aug then Q2 would reflect that month.

Stream Q1  Q2     Q3           Q4

Dev      0$   0$      16,66K    25K

 

Your help is appreicated.

 

Thank you

4 REPLIES 4
danextian
Super User
Super User

Hi @antoinetohme,

 

I think for your use case, it would be simpler to compute for the daily salary instead of dividing the salary by 4 to get the quarterly rate as not all start dates fall in the first day of the month and not all months have the same number of days.  This can easily done using Power Query. This approach will make your DAX calculations simpler.

Here's a sample M Script that demostrates what I just mentioned.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckktU9JR8krMUzDUUTAyMDIC8gwNDHQMDAyUYnWilYITc1KLgWK+iUUKxggVRpgqvEpzKnEYEuALFPBPLlEwNEDImyDkoY4oRXMEWDoWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Stream = _t, #"Start Date" = _t, #"Annual Salary" = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Index",{{"Stream", type text}, {"Start Date", type date}, {"Annual Salary", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Days to Next Year", each let
start = [Start Date],
end = #date(Date.Year(start) + 1, Date.Month(start), Date.Day(start))
in
Number.From( end - start) + 1, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Dates", each List.Dates([Start Date], [Days to Next Year], #duration(1, 0, 0, 0) )),
    #"Inserted Division" = Table.AddColumn(#"Added Custom1", "Daily Salary to Year End", each [Annual Salary] / [Days to Next Year], type number),
    #"Expanded Dates" = Table.ExpandListColumn(#"Inserted Division", "Dates"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Dates",{{"Dates", type date}})
in
    #"Changed Type1"

 

And here's how it can look in the report view.

danextian_0-1652921863379.png

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thank you @danextian 

What DAX function did you use to get that report view?

Also are you able to group the report by stream and sum up their salaries?

 

Thanks again

 

Hi @antoinetohme ,

 

I didn't create any calculated column or measure.  Here's a sample pbix for your reference -https://drive.google.com/file/d/1VoQ0wf67_r_Hat1vKxsnuPfIEBR5AoZU/view?usp=sharing 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
amitchandak
Super User
Super User

@antoinetohme , Create a date table and do not join it with this table , use qtr from date table in visual

Calendar that starts with any Standard Month — Just one variable apart https://medium.com/chandakamit/cheat-sheet-calendar-of-any-standard-month-just-one-variable-apart-5e...

 

 

 

Then try a measure like

 

calculate( Sumx(Table, Datediff(Table[Start Date], Max('Date'[Date]), Month) *[Annual Salary]/12), filter(Table, Table[Date] >= MIN('Date'[Date]) ))

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.