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
daveghowes
Frequent Visitor

Calculated Column returns Null value or not all values

I am stuck trying to get a calculated column working in PBI, if i try to - or + the results it returns some values but if i dont - or + it returns the value on that row. Long and short of it I am trying to put the date from the next row onto the current row, I have pasted an example below of some sample data 

Incident_NumberCreated_DateIndexRankWhat I getWhat I want 
126/05/2022 10:29112  
126/05/2022 00:5410126/05/2022 10:2926/05/2022 10:29
224/05/2022 10:5092 26/05/2022 00:54
223/05/2022 08:1881 24/05/2022 10:50
328/05/2022 15:2073 23/05/2022 08:18
328/05/2022 15:186228/05/2022 15:2028/05/2022 15:20
328/05/2022 15:175128/05/2022 15:1828/05/2022 15:18
430/05/2022 05:4144 28/05/2022 15:17
427/05/2022 05:0733 30/05/2022 05:41
427/05/2022 02:0722 27/05/2022 05:07
427/05/2022 01:071127/05/2022 02:0727/05/2022 02:07

 

My Sql query is pulling data and adding Index based on the ticket no and Rank based on Ticket no and the created_Date, 

the Calc column i am using is below, when using this i see a small amount of values. 

NextDate =
VAR var1 = 'Case Workgroup Assignement History (USE)'[Rank]
VAR var2 = 'Case Workgroup Assignement History (USE)'[Index]
RETURN
CALCULATE (
SUM ( 'Case Workgroup Assignement History (USE)'[Created_Date] ),
FILTER ( 'Case Workgroup Assignement History (USE)', 'Case Workgroup Assignement History (USE)'[Rank] = var1 + 1 && 'Case Workgroup Assignement History (USE)'[Index] = var2 )
)
 
daveghowes_0-1655298480853.png

The Index could go upto the millions and Rank can go into the 100s, as mentioned if i change the calc column abve to not - or + it returns a value on every row of the corresponding created_Date. I am wondering if the data being date and time is affecting it , but i cant be sure. 

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

Hi  ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can update the formula of the calculated column as below:

Column_NextDate = 
CALCULATE (
    MAX ( 'Case Workgroup Assignement History (USE)'[Created_Date] ),
    FILTER (
        'Case Workgroup Assignement History (USE)',
        'Case Workgroup Assignement History (USE)'[Index]
            = EARLIER ( 'Case Workgroup Assignement History (USE)'[Index] ) + 1
    )
)

yingyinr_0-1655715739606.png

Or you can create a meausre as below to get it:

NextDate = 
VAR _selindex =
    SELECTEDVALUE ( 'Case Workgroup Assignement History (USE)'[Index] )
VAR _preindex =
    CALCULATE (
        MIN ( 'Case Workgroup Assignement History (USE)'[Index] ),
        FILTER (
            ALLSELECTED ( 'Case Workgroup Assignement History (USE)' ),
            'Case Workgroup Assignement History (USE)'[Index] > _selindex
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Case Workgroup Assignement History (USE)'[Created_Date] ),
        FILTER (
            ALLSELECTED ( 'Case Workgroup Assignement History (USE)' ),
            'Case Workgroup Assignement History (USE)'[Index] = _preindex
        )
    )

yingyinr_2-1655715820737.png

If the above one can't help you get the desired result, 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.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi  ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can update the formula of the calculated column as below:

Column_NextDate = 
CALCULATE (
    MAX ( 'Case Workgroup Assignement History (USE)'[Created_Date] ),
    FILTER (
        'Case Workgroup Assignement History (USE)',
        'Case Workgroup Assignement History (USE)'[Index]
            = EARLIER ( 'Case Workgroup Assignement History (USE)'[Index] ) + 1
    )
)

yingyinr_0-1655715739606.png

Or you can create a meausre as below to get it:

NextDate = 
VAR _selindex =
    SELECTEDVALUE ( 'Case Workgroup Assignement History (USE)'[Index] )
VAR _preindex =
    CALCULATE (
        MIN ( 'Case Workgroup Assignement History (USE)'[Index] ),
        FILTER (
            ALLSELECTED ( 'Case Workgroup Assignement History (USE)' ),
            'Case Workgroup Assignement History (USE)'[Index] > _selindex
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Case Workgroup Assignement History (USE)'[Created_Date] ),
        FILTER (
            ALLSELECTED ( 'Case Workgroup Assignement History (USE)' ),
            'Case Workgroup Assignement History (USE)'[Index] = _preindex
        )
    )

yingyinr_2-1655715820737.png

If the above one can't help you get the desired result, 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.

How to upload PBI in Community

Best Regards

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

Hi,

 

Sorry for not replying sooner, this worked thank you. I actually realised the problem in my source data which was causing the issue also. Basically on my Rank column the numbering was going 1,3,4,6,7,8,9 etc because some columns were being filtered out. i removed the filter and this fixed the measures. i now need to fix my SQL query to only pull the rows i actually need. 

Thank you so much 

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.