Skip to content

Instantly share code, notes, and snippets.

View IvanBond's full-sized avatar

Ivan Bondarenko IvanBond

View GitHub Profile
(num as number, optional string as nullable text) =>
let
input_string = if string = null then "" else string,
reminder = Number.Mod( num, 2 ),
resulting_string = Text.From( reminder ) & input_string,
input = Number.IntegerDivide( num, 2 ),
r = if input > 0 then
Function IsWBHasCubeFormulas(Optional Wb As Workbook) As Boolean
Dim sh As Worksheet
Dim cell As Range
Dim bFound As Boolean
Dim bScreenUpdatingInitial As Boolean
Dim bEnableEventsInitial As Boolean
Dim CalcModeInitial As Integer
Dim rngFormulas As Range
On Error GoTo ErrHandler
' Wait function for VBA Excel
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#End If
' idea from ' http://www.fmsinc.com/microsoftaccess/modules/examples/avoiddoevents.asp
Sub WaitSeconds(intSeconds As Integer)
Dim datTime As Date
(url as text) as table =>
let
response = Web.Contents(url, [Headers=[Authorization=#"Authorization"]]),
body = Json.Document(response),
moreavailable = try Logical.From( body[more_available] ) otherwise false,
users = body[users],
#"Converted to Table" = Table.FromList(users, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1",
{"id", "state", "full_name", "job_title", "mugshot_url", "web_url", "activated_at", "stats", "email"},
{"id", "state", "full_name", "job_title", "mugshot_url", "web_url", "activated_at", "stats", "email"}),
let
Delay = 1, // X seconds
GroupID = Text.From( GroupID ), // from parameter GroupID
url_base = "https://www.yammer.com/api/v1/users/in_group/" & GroupID & ".json",
Source = List.Generate(
()=> [
i = 2, // we get 1st page by using fGetUsersPage in arg1
url = url_base,
Page = fGetUsersPage(url_base), // 1st page
more = true,
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#End If
Dim bManualRefresh As Boolean
Sub ManualStart()
On Error Resume Next
@IvanBond
IvanBond / GetUsername.pq
Created June 8, 2019 13:45
Get USERNAME in Power Query
let
Source = Folder.Contents("C:\Users"),
// filter out Public folder as it may be accessed by scripts
#"Filtered out Public" = Table.SelectRows( Source, each [Name] <> "Public"),
// sort to get last accessed in the top row
#"Sort by Date accessed" = Table.Sort( #"Filtered out Public", {{"Date accessed", Order.Descending}}),
// filter out potential system folders
#"Expanded Attributes" = Table.ExpandRecordColumn(#"Sort by Date accessed", "Attributes",
{"Kind", "ReadOnly", "Hidden", "System"},
{"Kind", "ReadOnly", "Hidden", "System"}),
@IvanBond
IvanBond / PowerTrim.m
Last active March 7, 2024 13:03
PowerTrim function for Power Query
/*
Function removes double presents of specified characters.
By default remove double spaces and leading + ending spaces.
Like TRIM function in Excel
Original is taked from Ken Puls's blog
http://www.excelguru.ca/blog/2015/10/08/clean-whitespace-in-powerquery/
*/
// part of repository: https://github.com/IvanBond/pquery