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
newpbiuser01
Helper IV
Helper IV

Custom Sort X Axis to Show Blank Values at the End

Hello,

 

I have a bar chart with the dates being displayed on the X axis. The date column is also blank for certain records and is currently being sorted to always show up at the beginning of the axis (or the end if I sort in the descending order). To create a custom sort ID, I did the following:

1. Created a measure to get the max of the date, and another to get the minimum of the date

2. Created a calculated date table with the min and the max values from the measures in 1 and created a custom column using the Rankx function to assign a rank to the dates. 

3. Created a dummy table with a blank row for the date and a dummy index.

4. Combined the two tables in 2 & 3 using the union function and created my sort ID saying - if(isblank([date]),maxrank+1, rank)

5. Use the lookupvalue to get the rank for each date in the primary data table. 

 

Once this is generated, I figured I could now just go to the date column and go the "Sort by column" and sort by my rank column. However, I get an error saying  "A circular dependency was detected". How do I get around this error and sort my column so the blanks always show up at the end of the X axis?  Thank you so much for all your help. 

1 ACCEPTED SOLUTION

Hi, @newpbiuser01 ;

May be we need use power query : in power query create a new column .

1.group by date.

vyalanwumsft_0-1668058913673.png

 

2.sort by date.

vyalanwumsft_1-1668058913683.png

 

3.add index column.

vyalanwumsft_2-1668058913684.png

 

4.add conditional column and delete index column.

vyalanwumsft_3-1668058913685.png

 

 

45.expand spend column

vyalanwumsft_4-1668058913686.png

 

then apply it into desktop.

vyalanwumsft_5-1668058913687.png

 


Best Regards,
Community Support Team _ Yalan Wu
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

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi, @newpbiuser01 ;

You could create a table as follow:

DateTable = UNION(  ADDCOLUMNS( SUMMARIZE( FILTER('Table',[Date]<>BLANK()),[Date]),"sortid",RANKX('Table',[Date])),
SUMMARIZE(FILTER('Table',[Date]=BLANK()),[Date],"sortid",0))

Then create a column in table.

month = IF([Date]=BLANK(),BLANK(), FORMAT([Date],"mmm"))

vyalanwumsft_0-1667985487871.png

vyalanwumsft_1-1667985513573.png

The final show:

vyalanwumsft_2-1667985540790.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yalanwu-msft ,

Thank you! This works great when the data is all in the same year, but it doesn't when the year is different. I tried creating a year column similarly to the month to see if that would help. 😞 

Hi, @newpbiuser01 ;

May be we need use power query : in power query create a new column .

1.group by date.

vyalanwumsft_0-1668058913673.png

 

2.sort by date.

vyalanwumsft_1-1668058913683.png

 

3.add index column.

vyalanwumsft_2-1668058913684.png

 

4.add conditional column and delete index column.

vyalanwumsft_3-1668058913685.png

 

 

45.expand spend column

vyalanwumsft_4-1668058913686.png

 

then apply it into desktop.

vyalanwumsft_5-1668058913687.png

 


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-yalanwu-msft! This worked perfectly. I really appreciate your help! 

v-yalanwu-msft
Community Support
Community Support

Hi, @newpbiuser01 ;

A circular dependency is detected whenever two objects reference each other, in such a way that Power BI cannot process the objects.

Avoiding circular dependency errors in DAX - SQLBI

because i can't Reproduce your data. please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

Solved: How to upload PBI in Community - Microsoft Power BI Community


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yalanwu-msft ,

 

My spend data looks like the following: 

DateSpend
2012-10-30188
2012-10-11100
2012-11-13162
2012-10-27136
2012-11-08161
2012-10-31138
2012-11-17196
2012-10-21124
2012-10-13195
 115
 176
 162
 111
 159

 

When I try to plot it on a bar chart, I get the blanks at the beginning, followed by October and then November. 

newpbiuser01_1-1667917790868.png

To do that, I created two measures: 

MinDate = Min([Date])
MaxDate = max([Date])
and then created a calculated table using these dates: 
DateTable = CALENDAR([MinDate],[MaxDate])
I then created a calculated column in this DateTable to rank the dates in the date column - 
IndexID = RANKX('DateTable',[Date]). 
 
To add the rank for blank dates, I created another data table using the Enter Data functionality, and the table looks like this:
newpbiuser01_3-1667918252494.png

I then merge the two tables: 

SortTable = Union('DateTable','Dummy Table'
Finally, I add a calculated SortID column which assigns 0 to the sortID for date = blank, otherwise uses the ranked index: 
newpbiuser01_4-1667918762557.png

 

 

 Now I have a table that I can use to sort the date column, and am hoping to sort the date field in my original spend table with this SortID. So I created a relationship between the SortTable and the Spend table using the Date column and try to sort the Date by the SortID, but I get the following error: 

newpbiuser01_5-1667918892001.png

 

How can I sort my date column in a way so the blank dates get sorted at the end without a circular dependency? I'd really appreciate any help! Thank you!

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.