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
thecrueljoker
Employee
Employee

Calculating and grouping data for last one year with or without using datetable

I have a resource table similar to this:

ResourceTable

ResourceNameCreationTimeDeletionTimeResourceTypeCompanyName
N11/4/20191/1/1900R1C1
N22/4/20191/1/1900R2C2
N312/01/201801/01/2019R1C1
N410/01/201801/01/2019R3C1
N58/01/20181/1/1900R5C3
N66/01/201801/01/2019R1C3

 

As you can see, for a particular date 'EndDate', a resource can be called 'Active' if it satisfies the following formula:

CreationTime<=EndDate AND (DeletionTime==1/1/1900 OR DeletionTime>EndDate)

 

I need to calculate trends for number of creates over the period of say last 365 days.
I also need trends per ResourceType, per resourcetype per company etc

 

Today i am able to get trends of creates over 365 days by doing the following:
Create a new Date table Last365Days with dates of last 365 days
Create a new Column

 

Total Resources = CALCULATE(COUNT(ResourceTable[ResourceName]),FILTER(ResourceTable,AND(ResourceTable[CreationTime]<=Last365Days[End Date],OR(ResourceTable[DeletionTime].[Year]=1900,ResourceTable[DeletionTime]>Last365Days[End Date]))))

 

But since this is a calculated column on a different table, I cannot group this by ResourceType or CompanyName.
If i want that, with this approach i will have to create a new column per company name or per resource type on Last365Days table. Like this:

 

Total C1 Resources = CALCULATE(COUNT(ResourceTable[ResourceName]),FILTER(ResourceTable,AND(ResourceTable[CompanyName] = "C1",AND(ResourceTable[CreationTime]<=Last365Days[End Date],OR(ResourceTable[DeletionTime].[Year]=1900,ResourceTable[DeletionTime]>Last365Days[End Date])))))

 


Is there a better way to group per companyname/resourcetype/both without creating a new column per resource/company? Especially since company is a field that can keep having new values in future.  Or is there a better way to get the data i am calculating? 
Am I missing something basic?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Not sure, seems like Open Tickets: https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/td-p/409364


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
karun_r
Employee
Employee

Can't you create a metric for Total Resources using your logic and a separate data dimension? I am not sure why we would have to store all prior dates in a separate table and calculate the count of resources created. If it's a measure, you can use any column of your choice to slice it across. Let me know if I am missing anything here about the problem statement.

The reason why i had to create a separate date table is because i want to calculate growth for every single day in last 365days. And i wanted this date to be the input towards my formula for calculating what can be called 'Active'. I was able to use one of the solutions suggested here and achieve it. Created a measure that took the date from date table as input and calculate whats active using my formula

Greg_Deckler
Super User
Super User

Not sure, seems like Open Tickets: https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/td-p/409364


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors