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
GlassShark1
Helper III
Helper III

Dynamic Columns and Grouping: Getting X year from a list of years

Struggling to find ways of maniplating dataframes dynamically. 

When pivoting a column, is there any way of keeping track of how many columns you have created? Or is there any way of tracking the 'position' of a date value within a list (e.g. 'the date value 31/03/2022 is the third value in the list sequentially')

 

My Fact table has a column for sales year (always 31st March 20XX), and another column for number of products sold. I pivot this to get these dates as columns and sales as values, so i can then replace any null values for the next part of my calculation, where i unpivot back again so each product has a row regardless if it has a sale in that year or not (I do it this way for a cummulative calculation). 

Later i want to be able compare these figures to a rolling target. Say our sales target for 2030 was 1,000, i would then divide the target by however many years to get a position we should ideally be in at a particular year (e.g. at year '3', it should be 3 x 10/1000). What i'm stuck on is how to get to "there are 6 dates in the column, X is the third date in the list sequentially' so i can then apply the target calculation.


Any ideas?


Thanks 🙂  

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @GlassShark1 

According to your original thread description, I guess you want to track the 'position' of a date value within a list, I think you can achieve this by adding an index column in the Power query editor, like this:

v-robertq-msft_0-1605840365881.png

Before adding the index column, you should sort ascending to make sure the date column is in positive order.

 

If you still have a problem, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hi, @GlassShark1 

According to your original thread description, I guess you want to track the 'position' of a date value within a list, I think you can achieve this by adding an index column in the Power query editor, like this:

v-robertq-msft_0-1605840365881.png

Before adding the index column, you should sort ascending to make sure the date column is in positive order.

 

If you still have a problem, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

GlassShark1
Helper III
Helper III

Sorry - what i'm trying to do as a whole is quite complicated. 

For this bit though, i'm basically asking how in a column of dates (essentally years), i can 'rank' them - so '1' is the earliest, '2' the next, etc etc.

GlassShark1_0-1605695864800.png


Annoyingly thinking about it, i can probably do this with RANKX?

 

Thanks 🙂

amitchandak
Super User
Super User

@GlassShark1 ,The information you have provided is not making the problem clear to me. Can you please explain with an example. Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Appreciate your Kudos.

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.