converting excel macrofields wor

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Power BI training and help » Converting Excel Macro-Fields Worksheets into PowerBI Visualisat

Converting Excel Macro-Fields Worksheets into PowerBI Visualisat

resolvedResolved · High Priority · Version 2016

Converting Excel Macro-Fields Worksheets into PowerBI Visualisat

Hello,


I have an Excel file which includes Macro-Fields, and I would like to convert a file by importing this into PowerBI environment. So, I can present the outcome on graphs.

For some reason, when I try to import the file using 'Import>Power Query, Power Pivot' , PowerBI says that migration is failed because the given file doesn't include any queries or a model.

Any suggestions, how to approach this problem?


Thank You!

RE: Converting Excel Macro-Fields Worksheets into PowerBI Visual

Hi Piotr,

Thank you for the forum question.

If you want to import data from Excel (not connect to data). You can only import a data model (Power Pivot) created in Excel, a query created in Power Query in Excel, or visuals created in Power View in Excel.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Converting Excel Macro-Fields Worksheets into PowerBI Visual

Hi Jens,


Thank you for your response, it was really helpful!


I might have to ask you also about macro fields itself.

For example, If I have a specific button in excel and its behaviour is specified with macros (i.e. if I click on it it will refresh/add/remove item from the list) , will I be able to re-create the same button with same functionality in PowerBI?


Thank You!

RE: Converting Excel Macro-Fields Worksheets into PowerBI Visual

Hi Piotr,

It is difficult to give you a straight answer. I do not know exactly what your macro is doing, but the query in Power Bi can automate almost everything.

When you write (i.e. if I click on it it will refresh/add/remove item from the list) do you mean that it adds new records and remove old records?

You can code the query but the code will auto execute. It is not like a macro you will have to execute to get the job done.

If you could explain in more details what you need to do or if you could copy the VBA code and paste it here, I can see what you want to do.

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Converting Excel Macro-Fields Worksheets into PowerBI Visual

Hello Jens,

Thank you for your last message.

Would you be able to explain the code (pasted below), which indicates a Macro function for "Refreshing List" with items in my Excel file. And would be possible to convert this code via DAX? So in theory, I'm thinking about creating the button inside PowerBI which would connect with the server via Macros and kick off the outcome in my table. Is this is something that it can be done?

There is also an easier solution, to give an "Action" to the button and link the button via external URL, which would connect with my Excel file via sharepoint.


But please let me know if the first solution (translating VBA code into DAX), can be also an option?

Here is the code:

Sub Update_QuoteStatus()

Application.ScreenUpdating = False

Dim lastrow As Long
Dim Item As Range
Dim cs As Variant
Dim i As Long

If Sheet6.Range("AI5").Value > 0 Then GoTo ErrorHandler1

lastrow = Sheet6.Cells(Rows.Count, 28).End(xlUp).Row

For i = 8 To lastrow
cs = Sheet6.Cells(i, 28).Value
With Sheet2
Set Item = .Cells.Find(What:=cs, After:=.Cells(1, 1), _
LookIn:=xlValues, lookat:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
End With

If Sheet6.Cells(i, 57) = 1 Then
Sheet2.Range(Item.Address).Offset(0, 1) = Sheet6.Cells(i, 8)
End If

If Sheet6.Cells(i, 67) = 1 Then
Sheet2.Range(Item.Address).Offset(0, 22) = Sheet6.Cells(i, 18)
End If

If Sheet6.Cells(i, 68) = 1 Then
Sheet2.Range(Item.Address).Offset(0, 13) = Sheet6.Cells(i, 19)
End If

If Sheet6.Cells(i, 71) = 1 Then
Sheet2.Range(Item.Address).Offset(0, 16) = Sheet6.Cells(i, 22)
End If

If Sheet6.Cells(i, 72) = 1 Then
Sheet2.Range(Item.Address).Offset(0, 17) = Sheet6.Cells(i, 23)
End If

If Sheet6.Cells(i, 74) = 1 Then
Sheet2.Range(Item.Address).Offset(0, 2) = Sheet6.Cells(i, 25)
End If

If Sheet6.Cells(i, 75) = 1 Then
Sheet2.Range(Item.Address).Offset(0, 43) = Sheet6.Cells(i, 26)
End If

Next i

Application.ScreenUpdating = True
Sheet6.Range("H7").Select

MsgBox ("Quote Data Updated")

Call Refresh_QuoteList

Exit Sub

ErrorHandler1:

Application.CutCopyMode = False
Application.ScreenUpdating = True
Sheet6.Range("H7").Select

MsgBox Prompt:="DATA REQUIRED" & vbNewLine & "Please update cells highlighted in yellow"


End Sub

Sub Refresh_QuoteList()

Application.ScreenUpdating = False

Dim pt1 As PivotTable
Dim Field1 As PivotField
Dim NewCat1 As String

Set pt1 = Sheet6.PivotTables("PivotTable1")
Set Field1 = pt1.PivotFields("Category1")
NewCat1 = Sheet6.Range("E20").Value

On Error GoTo ErrorHandler2

With pt1
Field1.ClearAllFilters
Field1.CurrentPage = NewCat1
pt1.RefreshTable
End With

Sheet6.Range("AK8:BC506").Copy
Sheet6.Range("H8:Z506").PasteSpecial Paste:=xlPasteValues

Application.CutCopyMode = False
Application.ScreenUpdating = True
Sheet6.Range("H7").Select

Exit Sub

ErrorHandler2:

With pt1
Field1.ClearAllFilters
Field1.CurrentPage = "(blank)"
pt1.RefreshTable
End With

Sheet6.Range("AK8:BC506").Copy
Sheet6.Range("H8:Z506").PasteSpecial Paste:=xlPasteValues

Application.CutCopyMode = False
Application.ScreenUpdating = True
Sheet6.Range("H7").Select

MsgBox Prompt:=("No '" & Sheet6.Range("E20").Value & "' items to list")

End Sub

Sub QuoteData_Revert()

Application.ScreenUpdating = False

Sheet6.Range("AK8:BC506").Copy
Sheet6.Range("H8:Z506").PasteSpecial Paste:=xlPasteValues

Application.CutCopyMode = False
Application.ScreenUpdating = True
Sheet6.Range("H7").Select

End Sub




Kind Regards,

Piotr Jedrzejczyk

RE: Converting Excel Macro-Fields Worksheets into PowerBI Visual

Hi Piotr,

I fully understand the code. Based on criteria it finds and move information and create a Pivot Table (short version)

I cannot say if you can do exactly what the VBA is doing in Power BI, and best practice is to have the source data issues sorted before connecting the data to the model in Power Bi.

In DAX we can write create table code, which will create new tables based on other tables and criteria, but you will not in DAX be able to create a button, which execute the DAX. DAX code will auto execute. Just like an Excel function. If numbers change the Excel function will execute and recalculate.

May be the best solution is to run the macro in Excel and from Power Bi create a connection to the file and the create the visuals.




Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Converting Excel Macro-Fields Worksheets into PowerBI Visual

Hello Jens,



Thank you for your response.

I believe that linking PowerBI to the excel file on the server, will be the best solution, as we agreed to the point that DAX can be only auto-executed.

I think that answers all my questions.

Thank you for your support.


Kind Regards

Piotr Jedrzejczyk

 

Training courses

 

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Power BI tip:

Optimize Report Performance

Pay attention to report performance by optimizing your data model and report design. Use the Performance Analyzer tool to identify bottlenecks in your report and improve loading times. Techniques such as using summarisation, avoiding unnecessary visuals, and optimizing DAX queries contribute to a faster and more responsive report.

View all Power BI hints and tips


Server loaded in 0.08 secs.