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

Calculate Table

Hi guys.

 

I'm trying to transform the following table:

TicketOpenCloseAge
abc01/jan10/jan10
def01/jan01/fev32
ghi01/jan10/fev41
jkl01/jan10/mar70

 

in this:

TicketPeriodDays by Month
abc01/jan10
def01/jan31
ghi01/jan31
jkl01/jan31
def01/fev1
ghi01/fev10
jkl01/fev29
jkl01/mar10

 

The question that I need to answer is: How long has a ticket been open each month?

 

Tks guys!!

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

Hi @Anonymous ,

 

1.My sample data is this.

Ticket

Age

Open

Close

abc

10

01/Jan

10/Jan

def

32

01/Jan

01/Feb

ghi

41

01/Jan

10/Feb

jkl

70

01/Jan

10/Mar

 

2.Create calculated columns to get Open date and Close date.

OpenDate = 
VAR month =
    SWITCH (
        RIGHT ( 'Table'[Open], 3 ),
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12,
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6
    )
RETURN
    DATE ( 2020, month, LEFT ( 'Table'[Open], 2 ) )
CloseDate = 
VAR month =
    SWITCH (
        RIGHT ( 'Table'[Close], 3 ),
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12,
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6
    )
RETURN
    DATE ( 2020, month, LEFT ( 'Table'[Close], 2 ) )

4.png

 

3.Create a calendar table.

Dates =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2020, 12, 31 ) ),
    "day", DAY ( [Date] ),
    "Period",
        DAY ( [Date] ) & "/"
            & FORMAT ( [Date], "mmm" )
)

5.png

 

4.Create a new table which is a combination and filtering of the previous two tables.

NewTable =
SUMMARIZE (
    ADDCOLUMNS (
        FILTER (
            CROSSJOIN ( 'Dates', 'Table' ),
            [Date] <= [CloseDate]
                && [Date] >= [OpenDate]
                && [day] = 1
        ),
        "Days by Month",
            IF (
                EOMONTH ( [Date], 0 ) < [CloseDate],
                DAY ( EOMONTH ( [Date], 0 ) ),
                DAY ( [CloseDate] )
            )
    ),
    [Ticket],
    [Period],
    [Days by Month]
)

 6.png

 

You can check more details from here.

 

 

 

Best Regards,

Stephen Tao

 

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-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

1.My sample data is this.

Ticket

Age

Open

Close

abc

10

01/Jan

10/Jan

def

32

01/Jan

01/Feb

ghi

41

01/Jan

10/Feb

jkl

70

01/Jan

10/Mar

 

2.Create calculated columns to get Open date and Close date.

OpenDate = 
VAR month =
    SWITCH (
        RIGHT ( 'Table'[Open], 3 ),
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12,
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6
    )
RETURN
    DATE ( 2020, month, LEFT ( 'Table'[Open], 2 ) )
CloseDate = 
VAR month =
    SWITCH (
        RIGHT ( 'Table'[Close], 3 ),
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12,
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6
    )
RETURN
    DATE ( 2020, month, LEFT ( 'Table'[Close], 2 ) )

4.png

 

3.Create a calendar table.

Dates =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2020, 12, 31 ) ),
    "day", DAY ( [Date] ),
    "Period",
        DAY ( [Date] ) & "/"
            & FORMAT ( [Date], "mmm" )
)

5.png

 

4.Create a new table which is a combination and filtering of the previous two tables.

NewTable =
SUMMARIZE (
    ADDCOLUMNS (
        FILTER (
            CROSSJOIN ( 'Dates', 'Table' ),
            [Date] <= [CloseDate]
                && [Date] >= [OpenDate]
                && [day] = 1
        ),
        "Days by Month",
            IF (
                EOMONTH ( [Date], 0 ) < [CloseDate],
                DAY ( EOMONTH ( [Date], 0 ) ),
                DAY ( [CloseDate] )
            )
    ),
    [Ticket],
    [Period],
    [Days by Month]
)

 6.png

 

You can check more details from here.

 

 

 

Best Regards,

Stephen Tao

 

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

 

FrankAT
Community Champion
Community Champion

Hello @Williamspsouza

you can do this with Power Query as follows:

// Table
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMjDUByIjAyMDIMfQAIWjFKsTrZSSmoauDMQxgnGMjcDK0jMysZkGV2ZiCFaWlZ2DTZkxjGMOtDQWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ticket = _t, Open = _t, Close = _t, Age = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ticket", type text}, {"Open", type date}, {"Close", type date}, {"Age", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {Number.From([Open]).. Number.From([Close])}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}}),
    #"Inserted Month" = Table.AddColumn(#"Changed Type1", "Month", each Date.Month([Custom]), Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Inserted Month", "Day", each 1),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"Day", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type2", {"Ticket", "Month"}, {{"Sum", each List.Sum([Day]), type nullable number}}),
    #"Added Custom2" = Table.AddColumn(#"Grouped Rows", "Period", each #date(2020,[Month],1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Month"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Ticket", "Period", "Sum"}),
    #"Changed Type3" = Table.TransformColumnTypes(#"Reordered Columns",{{"Period", type date}})
in
    #"Changed Type3"

03-09-_2020_01-32-18.png

No Bothers With The Date Format. That It In The Way From I Region.
With kind greetings from the city where the legend of the 'Pied Piper de Hamelin' is at home
FrankAT (Proud to be a Datanaut)
Ashish_Mathur
Super User
Super User

Hi,

Download my PBI file from here.

Hope this helps.

Untitled.png


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

@Anonymous - Check out Open Tickets. It will be the same basic concept. https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

I appreciate the answer but it doesn’t answer my question.  How long has a ticket been open each month?

Hi,

Have you checked my result?


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

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.