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
aBerg
Helper II
Helper II

Creating new table out of existing one and grouping by time

Hi.

 

I would like help with an application in PBI Desktop. I don't know how to start... Smiley Frustrated


I have to create a simple line chart to compare an "Energy measure" (fMP table) with a "Weight/Time measure" (fMPPr table), however the granularity of the "fMP table" is each 15 minutes and the data in the "fMPPr table" is per event, that is, each row has a time interval of hours&minutes.
I need to compare two measurements at the same time base (15 minutes granularity), so I first have to divide each row into several rows of minute granularity and then group the data by 15 minutes (same granularity as the fMP table). I created a drawing demonstrating my need and also the .pbix application link .PBIX.

 

table.png

 

If anyone can help in how to do it I thank you immensely. Smiley Happy I have no idea how to start ... 

 

Greetings !

1 ACCEPTED SOLUTION

Hi @aBerg

 

You can create a new calculated table as follows. It's a long piece of code. I'm sure it can be done in a shorter fashion but I ain't yet had time to trim it down. The columns of interest are [Expanded Date/Time] and [Weight/Time per 15 mins]. You can further manipulate the resulting table to select only specific columns or change their name if required.

 

NewTable2 = 
FILTER (
    VAR _OneMinute = 1 / 24 / 60
    VAR _ExpandedTable =
        GENERATE (
            fMPPr;
            VAR _CurrentTime = fMPPr[Date&Time]
            VAR _NextTimeAux =
                CALCULATE (
                    MIN ( fMPPr[Date&Time] );
                    ALL ( fMPPr );
                    fMPPr[Date&Time] > EARLIER ( fMPPr[Date&Time] )
                )
            VAR _NextTime =
                IF ( NOT ISBLANK ( _NextTimeAux ); _NextTimeAux; _CurrentTime ) //The IF is to avoid expansion in the very last Date/Time 
            VAR _ResultTable =
                SELECTCOLUMNS (
                    GENERATESERIES ( _CurrentTime; _NextTime; _OneMinute );
                    "Expanded Date/Time"; [Value];
                    "Expanded Weight/Time"; [Weight/Time]
                )
            RETURN
                _ResultTable
        )
    RETURN
        ADDCOLUMNS (
            _ExpandedTable;
            "Weight/Time per 15 mins"; IF (
                MINUTE ( [Expanded Date/Time] ) IN { 0; 15; 30; 45 };
                SUMX (
                    FILTER (
                        _ExpandedTable;
                        DATEDIFF ( [Expanded Date/Time]; EARLIER ( [Expanded Date/Time] ); MINUTE ) >= 1
                            && DATEDIFF ( [Expanded Date/Time]; EARLIER ( [Expanded Date/Time] ); MINUTE ) <= 15
                    );
                    [Expanded Weight/Time]
                )
            )
        );
    NOT ISBLANK ( [Weight/Time per 15 mins] )
)

 

Code formatted with   www.daxformatter.com

View solution in original post

11 REPLIES 11

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.