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
Anonymous
Not applicable

Calculated column using data from multiple rows and columns

Hi, I've been stuck at a problem for a while now. I checked multiple other questions like mine but I wasn't able to find the right answer so I thought I'd ask. My situation looks like this: 

 

ValueSubIndexFrameIDDateSOLUTION
34THXY221.1.2020(BLANK)
505THXY221.1.2020(BLANK)
555THXY247.2.20201,0416...
441THXY247.2.20201,0416...
1206THXY247.2.20201,0416...
201THXY249.5.20203
605THXY249.5.20203
1006THXY249.5.20203
331THXY2511.6.2020...

 

I'm not sure if this is even possible in a single step but so far my ideas have only led to error messeges. I have the above data (with more rows which I'll leave out for clarity and more columns which are irrelevant to the calculation) and I am supposed to do the following: 

 

There are always 2 or 3 rows per date and FrameID. I need to calculate a number with the values of the rows for every FrameID using a formula and then enter that number in the solution column at the end (red column). The formula for a FrameID is SOLUTION = ((100 * value(row w/ the SubIndex 5))/value(row w/ the SubIndex 1))/value(row w/ the SubIndex 6). In the case of the FrameID THXY24 and Date 7.2.2020 this give us ((100*55)/44)120 = 1,0416... . In the case of there only being rows with the SubIndexes 1 and 5 given for a FrameID (as is the case for FrameID THXY22) then we cannot calculate anything so the entry should be blank. There may be more than 3 rows per FrameID but they will always be distinguishable by the date. I need to calculate the solution for each FrameID (if possible, otherwise I need to add the blank) and enter it in the solution column but I am completely stuck (I'm a novice). Is there any way to do this?

 

Any help wouls be appreciated, thanks!

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

Here is one way to approach this in a calculated column.  Please try this expression.

 

 

Result =
VAR index1 =
    CALCULATE (
        MIN ( Frame[Value] ),
        ALLEXCEPT ( Frame, Frame[FrameID], Frame[Date] ),
        Frame[SubIndex] = 1
    )
VAR index5 =
    CALCULATE (
        MIN ( Frame[Value] ),
        ALLEXCEPT ( Frame, Frame[FrameID], Frame[Date] ),
        Frame[SubIndex] = 5
    )
VAR index6 =
    CALCULATE (
        MIN ( Frame[Value] ),
        ALLEXCEPT ( Frame, Frame[FrameID], Frame[Date] ),
        Frame[SubIndex] = 6
    )
RETURN
    IF ( NOT ( ISBLANK ( index6 ) ), 100 * DIVIDE ( index5, index1 ) / index6 )

 

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=DIVIDE(DIVIDE(100*CALCULATE(SUM(Data[Value]),FILTER(Data,Data[FrameID]=EARLIER(Data[FrameID])&&Data[Date]=EARLIER(Data[Date])&&Data[SubIndex]=5)),CALCULATE(SUM(Data[Value]),FILTER(Data,Data[FrameID]=EARLIER(Data[FrameID])&&Data[Date]=EARLIER(Data[Date])&&Data[SubIndex]=1))),CALCULATE(SUM(Data[Value]),FILTER(Data,Data[FrameID]=EARLIER(Data[FrameID])&&Data[Date]=EARLIER(Data[Date])&&Data[SubIndex]=6)))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@mahoneypat @Ashish_Mathur Thank you both. Both of your solutions worked perfectly. 

You are welcome.  If my reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=DIVIDE(DIVIDE(100*CALCULATE(SUM(Data[Value]),FILTER(Data,Data[FrameID]=EARLIER(Data[FrameID])&&Data[Date]=EARLIER(Data[Date])&&Data[SubIndex]=5)),CALCULATE(SUM(Data[Value]),FILTER(Data,Data[FrameID]=EARLIER(Data[FrameID])&&Data[Date]=EARLIER(Data[Date])&&Data[SubIndex]=1))),CALCULATE(SUM(Data[Value]),FILTER(Data,Data[FrameID]=EARLIER(Data[FrameID])&&Data[Date]=EARLIER(Data[Date])&&Data[SubIndex]=6)))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Employee
Employee

Here is one way to approach this in a calculated column.  Please try this expression.

 

 

Result =
VAR index1 =
    CALCULATE (
        MIN ( Frame[Value] ),
        ALLEXCEPT ( Frame, Frame[FrameID], Frame[Date] ),
        Frame[SubIndex] = 1
    )
VAR index5 =
    CALCULATE (
        MIN ( Frame[Value] ),
        ALLEXCEPT ( Frame, Frame[FrameID], Frame[Date] ),
        Frame[SubIndex] = 5
    )
VAR index6 =
    CALCULATE (
        MIN ( Frame[Value] ),
        ALLEXCEPT ( Frame, Frame[FrameID], Frame[Date] ),
        Frame[SubIndex] = 6
    )
RETURN
    IF ( NOT ( ISBLANK ( index6 ) ), 100 * DIVIDE ( index5, index1 ) / index6 )

 

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.